I'm following the Django Tutorials, I'm at the end of part 3, at Decoupling the URLconfs, at http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03 and I'm getting a "No module named urls" error message.
When I change:
from django.conf.urls.defaults import * from django.contrib import admin admin.autodiscover() urlpatterns = patterns('mysite.polls.views', (r'^polls/$', 'index'), (r'^polls/(?P<poll_id>\d+)/$', 'detail'), (r'^polls/(?P<poll_id>\d+)/results/$', 'results'), (r'^polls/(?P<poll_id>\d+)/vote/$', 'vote'), (r'^admin/', include(admin.site.urls)), )
to:
from django.conf.urls.defaults import * from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', (r'^polls/', include('mysite.polls.urls')), (r'^admin/', include(admin.site.urls)), )
I changed
include('mysite.polls.urls')),
toinclude(mysite.polls.urls)),
, but it still didn't work.How to solve this problem?
UPDATE 2: at mysite/polls/urls.py is
from django.conf.urls.defaults import * urlpatterns = patterns('mysite.polls.views', (r'^$', 'index'), (r'^(?P<poll_id>\d+)/$', 'detail'), (r'^(?P<poll_id>\d+)/results/$', 'results'), (r'^(?P<poll_id>\d+)/vote/$', 'vote'), )
UPDATE 4: the whole project is at
score:8
I can't re-produce the import error on my machine using your project files (Windows 7, Django 1.1.1, Python 2.6.4). Everything imported fine but the urls were not specified properly (like the tutorial shows). Fixing the code:
/mysite/urls.py:
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^polls/', include('mysite.polls.urls')),
(r'^admin/', include(admin.site.urls)),
)
/mysite/polls/urls.py:
from django.conf.urls.defaults import *
urlpatterns = patterns('mysite.polls.views',
(r'^$', 'index'),
(r'^(?P<poll_id>\d+)/$', 'detail'),
(r'^(?P<poll_id>\d+)/results/$', 'results'),
(r'^(?P<poll_id>\d+)/vote/$', 'vote'),
)
Visit http://127.0.0.1:8000/polls/ - I received a TemplateDoesNotExist exception because the template file is missing.
I'm afraid my answer might be to reboot and try it again. ;)
Similar question
- Django: from django.urls import reverse; ImportError: No module named urls
- No module named urls
- Django: ImportError, No module named urls
- Django - ImportError at /blog. No module named urls
- ImportError at / No module named urls
- Django, tutorial - error: No module named urls
- Python-Django : ImportError at / : No module named urls
- No module named urls / no response with django + mod_wsgi
- How to fix ImportError: No module named urls
- Django Import Error at / No module named urls
score:0
Like Ryan Bagwell, problem was (at least temporarily) solved by changing ROOT_URLCONF in myproject/myproject/settings.py. I had to add "myproject" to ROOT_URLCONF to have there this: "%s.myproject.urls" % PROJECT_APP
score:1
I did exactly the same thing. Python newbie mistake by reading ahead. I created a file call "polls.url" thinking it was some sort of special django template file.
I misunderstood the text: "Now that we've decoupled that, we need to decouple the polls.urls URLconf by removing the leading "polls/" from each line, and removing the lines registering the admin site. Your polls.urls file should now look like this: "
It should really read: "Now that we've decoupled that, we need to decouple the polls.urls URLconf by removing the leading "polls/" from each line, and removing the lines registering the admin site. Your polls/urls.py file should now look like this: "
Some more answer related to the same question
- No module named pkg_resources
- No module named MySQLdb
- ImportError: No module named 'django.core.urlresolvers'
- django import error - No module named core.management
- Django Rest Framework -- no module named rest_framework
- Django - "no module named django.core.management"
- Error: No module named psycopg2.extensions
- django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
- Django import error - no module named django.conf.urls.defaults
- Gunicorn, no module named 'myproject
score:1
Late to the party but I fixed my problem by correcting a typo inside settings.py INSTALLED_APPS. I had 'webbapp' instead of 'webapp' so you might want to check on that as well (for people still having the problem)
score:5
I also had a weird problem with "No module named mysite.urls". The admin site was down and the my whole site.
The solution, after a few hours of searching the web, was on my side : Django is caching some of the settings in a file that he knows from an environment variable.
I just closed my terminal in which i was doing the runnserver thing and opened a new one.
score:8
Is there an __init__.py
inside mysite/polls/ directory?
score:51
I had a similar problem in my project root ... django complained that it couldn't find the module mysite.urls.
Turns out my ROOT_URLCONF variable in settings.py, which was set up using the default values, was set incorrect. Instead of "mysite.urls", it should have been simply "urls"
I changed it, and voila, it worked.
Credit To: stackoverflow.com
Related Query
- ImportError: No module named virtualenv
- django.core.exceptions.ImproperlyConfigured: Error loading psycopg module: No module named psycopg
- "No module named simple" error in Django
- Running django tutorial tests fail - No module named polls.tests
- ImportError: No module named django.core.wsgi Apache + VirtualEnv + AWS + WSGI
- ImportError: No module named django_filters
- No module named 'polls.apps.PollsConfigdjango'; Django project tutorial 2
- No module named django but it is installed
- ImportError: No module named django.core.handlers.wsgi in install django mod_wsgi config on apache
- Import Error: No module named django
More Query from same tag
- Django: overriding Model.validate_unique
- Dynamically update ModelForm's Meta class
- Easy-to-use django captcha or registration app with captcha?
- Django : Two ways of caching template : What is the difference?
- Django forms: object has no attribute cleaned data
- Django ORM get respective choices value instead of field value
- Stop affecting other objects of Django Many to Many model
- Django-registration Admin
- Getting the request.user form pre_save in Django
- django-notifications-hq: cannot show notifications
- Unicode errror from Haystack indexing
- UnicodeDecodeError on attempt to save file through django default filebased backend
- django - 1. select 2. filter 3. then cut
- How do I patch a python method for a test case to run?
- How to rename a django model in an application by changing letter case