Opened 8 years ago
Closed 8 years ago
#27075 closed Bug (worksforme)
URLconf does not properly import underscore-containing module identifiers
Reported by: | Peter Lai | Owned by: | nobody |
---|---|---|---|
Component: | Core (URLs) | Version: | 1.10 |
Severity: | Normal | Keywords: | underscore, import |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If I have the following mysite\myapp\urls.py
:
from django.conf.urls import url from my_app import views, other_views urlpatterns = [ url(r'^$, views.index, name='index'), # OK url(r'^foo/', other_views.bar, name='getfoo'), ]
and in other_views.py
:
def bar(request): pass
This results in manage.py
raising:
File "C:\path\to\django_sites\mysite\mysite\urls.py", line 21, in <module> url(r'^myapp/', include('myapp.urls')), File "C:\path\to\py3_venv\django1\lib\site-packages\django\conf\urls\__init__.py", line 50, in include urlconf_module = import_module(urlconf_module) File "C:\path\to\py3_venv\django1\lib\importlib\__init__.py", line 109, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 2254, in _gcd_import File "<frozen importlib._bootstrap>", line 2237, in _find_and_load File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked File "<frozen importlib._bootstrap>", line 1129, in _exec File "<frozen importlib._bootstrap>", line 1471, in exec_module File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed File "C:\path\to\django_sites\mysite\myapp\urls.py", line 15, in <module> other_views.bar, name='getfoo'), AttributeError: 'module' object has no attribute 'bar'
Note that mysite\myapp\urls.py
is included via the mysite\mysite\urls.py
Renaming other_views.py
to otherviews.py
fixes the problem. Platform: Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32.
Note:
See TracTickets
for help on using tickets.
I don't think an underscore should make any difference as far as Django (Python, really) being able to import a module. I tried to reproduce this without success. Maybe you could provide a sample project to our support channels and reopen this ticket if it does turn out to be a problem in Django.