[Django] #34189: Code in Tutorial does not work because of a ','

0 views
Skip to first unread message

Django

unread,
Nov 29, 2022, 7:27:34 AM11/29/22
to django-...@googlegroups.com
#34189: Code in Tutorial does not work because of a ','
-----------------------------------------+------------------------
Reporter: rroger | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 4.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Page: https://docs.djangoproject.com/en/4.1/intro/tutorial01/

Code

{{{
from django.urls import path

from . import views

urlpatterns = [
path('', views.index, name='index'),
]
}}}

the ',' at the end of path(...) needs to be removed, otherwise an
exception is raised and the code does not work.

it should be:


{{{
from django.urls import path

from . import views

urlpatterns = [
path('', views.index, name='index')
]
}}}


I am sorry in case I violite some buge tracking conventions. I actually
want to continue with the tutorial, but wanted to raise the issue. Thanks
for the otherwise greate tutorial! :)

--
Ticket URL: <https://code.djangoproject.com/ticket/34189>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 29, 2022, 7:34:33 AM11/29/22
to django-...@googlegroups.com
#34189: Code in Tutorial does not work because of a ','
---------------------------------+--------------------------------------
Reporter: Roger Rüttimann | Owner: nobody
Type: Bug | Status: closed
Component: Documentation | Version: 4.1
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => invalid


Comment:

`urlpatterns` is a list and this example is a valid Python code. Trac is
not a support channel, so if you're having trouble understanding how
Python/Django works, see TicketClosingReasons/UseSupportChannels for ways
to get help.

--
Ticket URL: <https://code.djangoproject.com/ticket/34189#comment:1>

Django

unread,
Nov 29, 2022, 7:57:51 AM11/29/22
to django-...@googlegroups.com
#34189: Code in Tutorial does not work because of a ','
---------------------------------+--------------------------------------
Reporter: Roger Rüttimann | Owner: nobody
Type: Bug | Status: closed
Component: Documentation | Version: 4.1
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by Roger Rüttimann):

Thanks for the comment @Mariusz Felisiak, but even as the code might be
valid python, I still think its a bug, because this happens when I copy
paste the code of the tutorial and try to run the development server:


{{{
(cvmanager) ➜ cvmanager git:(main) ✗ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
File "/Users/rroger/py_virtualenvs/cvmanager/lib/python3.10/site-
packages/django/urls/resolvers.py", line 717, in url_patterns
iter(patterns)
TypeError: 'module' object is not iterable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File
"/opt/homebrew/Cellar/pyt...@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py",
line 1016, in _bootstrap_inner
self.run()
File
"/opt/homebrew/Cellar/pyt...@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py",
line 953, in run
self._target(*self._args, **self._kwargs)
File "/Users/rroger/py_virtualenvs/cvmanager/lib/python3.10/site-
packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/Users/rroger/py_virtualenvs/cvmanager/lib/python3.10/site-
packages/django/core/management/commands/runserver.py", line 134, in
inner_run
self.check(display_num_errors=True)
File "/Users/rroger/py_virtualenvs/cvmanager/lib/python3.10/site-
packages/django/core/management/base.py", line 475, in check
all_issues = checks.run_checks(
File "/Users/rroger/py_virtualenvs/cvmanager/lib/python3.10/site-
packages/django/core/checks/registry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/Users/rroger/py_virtualenvs/cvmanager/lib/python3.10/site-
packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "/Users/rroger/py_virtualenvs/cvmanager/lib/python3.10/site-
packages/django/core/checks/urls.py", line 24, in check_resolver
return check_method()
File "/Users/rroger/py_virtualenvs/cvmanager/lib/python3.10/site-
packages/django/urls/resolvers.py", line 495, in check
messages.extend(check_resolver(pattern))
File "/Users/rroger/py_virtualenvs/cvmanager/lib/python3.10/site-
packages/django/core/checks/urls.py", line 24, in check_resolver
return check_method()
File "/Users/rroger/py_virtualenvs/cvmanager/lib/python3.10/site-
packages/django/urls/resolvers.py", line 494, in check
for pattern in self.url_patterns:
File "/Users/rroger/py_virtualenvs/cvmanager/lib/python3.10/site-
packages/django/utils/functional.py", line 57, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/rroger/py_virtualenvs/cvmanager/lib/python3.10/site-
packages/django/urls/resolvers.py", line 725, in url_patterns
raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module
'cv.urls' from '/Users/rroger/workspace/cvmanager/cv/urls.py'>' does not
appear to have any patterns in it. If you see the 'urlpatterns' variable
with valid patterns in the file then the issue is probably caused by a
circular import.
}}}

and without the ',' it works as expected. I think code in a tutorial
should run without raisng exceptions.

--
Ticket URL: <https://code.djangoproject.com/ticket/34189#comment:2>

Django

unread,
Nov 29, 2022, 8:04:08 AM11/29/22
to django-...@googlegroups.com
#34189: Code in Tutorial does not work because of a ','
---------------------------------+--------------------------------------
Reporter: Roger Rüttimann | Owner: nobody
Type: Bug | Status: closed
Component: Documentation | Version: 4.1
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by Mariusz Felisiak):

> I still think its a bug, because this happens when I copy paste the code
of the tutorial and try to run the development server:

Maybe there is a bug but not in the tutorial or Django itself, but in your
code. You probably made some typo when copying code from the tutorial.
Please use one of
[https://code.djangoproject.com/wiki/TicketClosingReasons/UseSupportChannels
support channels].

--
Ticket URL: <https://code.djangoproject.com/ticket/34189#comment:3>

Django

unread,
Nov 29, 2022, 8:32:48 AM11/29/22
to django-...@googlegroups.com
#34189: Code in Tutorial does not work because of a ','
---------------------------------+--------------------------------------
Reporter: Roger Rüttimann | Owner: nobody
Type: Bug | Status: closed
Component: Documentation | Version: 4.1
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by Roger Rüttimann):

Actually your right, I tried to reprodcue it, but I can not. Now it's
working either way, with or without the comma.
Sorry for the unproductive ticket and thanks for the quick feedback!

--
Ticket URL: <https://code.djangoproject.com/ticket/34189#comment:4>

Reply all
Reply to author
Forward
0 new messages