Documentation request: Please include more examples and locations in the docs

Hi, the dogs have a lot of information but one thing I’ve noticed is that it doesn’t tell you WHERE you’re supposed to put some thing a lot of the time, and it lacks enough examples to fully understand for new users, or in my case new users is with learning disabilities.

Additionally, I would love to request the errors that Django reports include a file name and line number, so that they are easier to debug, I’m kind of surprised this doesn’t exist already.

I mean these errors are incredibly confusing. The last line or two should say where and what. How are we supposed to debug, say, this:

The last line just says
AttributeError: 'function' object has no attribute 'META'

With no information about where.

Thank you :slight_smile:

(P4)  ✘ iankleinfeld@ians-mac-mini  ~/Documents/GeneralAssembly/Django/P4   master ±  p3m showmigrations
python3 manage.py showmigrations
Traceback (most recent call last):
  File "/Users/iankleinfeld/Documents/GeneralAssembly/Django/P4/manage.py", line 22, in <module>
    main()
  File "/Users/iankleinfeld/Documents/GeneralAssembly/Django/P4/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/core/management/base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/core/management/base.py", line 453, in execute
    self.check()
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/core/management/base.py", line 485, in check
    all_issues = checks.run_checks(
                 ^^^^^^^^^^^^^^^^^^
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/core/checks/registry.py", line 88, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/core/checks/urls.py", line 14, in check_url_config
    return check_resolver(resolver)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/core/checks/urls.py", line 24, in check_resolver
    return check_method()
           ^^^^^^^^^^^^^^
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/urls/resolvers.py", line 516, in check
    for pattern in self.url_patterns:
                   ^^^^^^^^^^^^^^^^^
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/utils/functional.py", line 47, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
                                         ^^^^^^^^^^^^^^^^^^^
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/urls/resolvers.py", line 735, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
                       ^^^^^^^^^^^^^^^^^^^
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/utils/functional.py", line 47, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
                                         ^^^^^^^^^^^^^^^^^^^
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/urls/resolvers.py", line 728, in urlconf_module
    return import_module(self.urlconf_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 994, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/Users/iankleinfeld/Documents/GeneralAssembly/Django/P4/carsproj/urls.py", line 23, in <module>
    path('',include('carsapp.urls'))
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/urls/conf.py", line 38, in include
    urlconf_module = import_module(urlconf_module)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 994, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/Users/iankleinfeld/Documents/GeneralAssembly/Django/P4/carsapp/urls.py", line 2, in <module>
    from . import views
  File "/Users/iankleinfeld/Documents/GeneralAssembly/Django/P4/carsapp/views.py", line 46, in <module>
    @login_required
     ^^^^^^^^^^^^^^
  File "/Users/iankleinfeld/Documents/GeneralAssembly/Django/P4/carsapp/views.py", line 11, in login_required
    return render(request, 'registration/login.html')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/shortcuts.py", line 24, in render
    content = loader.render_to_string(template_name, context, request, using=using)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/template/loader.py", line 62, in render_to_string
    return template.render(context, request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/template/base.py", line 169, in render
    with context.bind_template(self):
  File "/usr/local/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/template/context.py", line 254, in bind_template
    context = processor(self.request)
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/iankleinfeld/.local/share/virtualenvs/P4-OyFIDtgQ/lib/python3.12/site-packages/django/template/context_processors.py", line 41, in debug
    if settings.DEBUG and request.META.get("REMOTE_ADDR") in settings.INTERNAL_IPS:
                          ^^^^^^^^^^^^
AttributeError: 'function' object has no attribute 'META'

Hi. Here is the where:

So, META attribute is searched on a request object which is a function, where Django would expect it to be the received request.

Going back in the traceback, we can see the request object is passed there:

So, you have to check your view to see what is the request passed to the render method.

May you share your views.py content so that we can help you debug.

You need to look at the stack trace as a whole.

The specific answer to your question is the line immediately above this.

That’s telling you the file and line number of the error, in addition to showing you the line that is throwing the error.

Now, because an error frequently doesn’t get thrown until well after the mistake is made, you need to examine the traceback to find the last line of code that you wrote (not what is provided by Django or Python) to identify the most likely cause of the problem.
(In this case, the section identified by the previous response.)

Regarding your other comment about “where” things belong - any particular line of code may be used in multiple locations, depending upon the situation and context of use. Very few things in the docs may only be used in one specific file or location, and it’s not practical to provide a comprehensive list of everywhere something can be used.