ImportError at /admin/

34 views
Skip to first unread message

Gagan (GPS)

unread,
Jun 13, 2011, 6:56:18 AM6/13/11
to Django users
I am having some difficulty accessing the admin of a project I am
trying to create.

My urls.py is the default with admin enabled:

from django.conf.urls.defaults import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Examples:
# url(r'^$', '{{ project_name }}.views.home', name='home'),
# url(r'^{{ project_name }}/',
include('{{ project_name }}.foo.urls')),

# Uncomment the admin/doc line below to enable admin
documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

url(r'^admin/', include(admin.site.urls)),
)


The traceback is as follows:


Environment:


Request Method: GET
Request URL: http://192.168.2.127:8000/admin/

Django Version: 1.4 pre-alpha SVN-16385
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'pagination',
'django_extensions',
'django.contrib.admin',
'events']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'pagination.middleware.PaginationMiddleware')


Traceback:
File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py"
in get_response
101. request.path_info)
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in
resolve
250. for pattern in self.url_patterns:
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in
_get_url_patterns
279. patterns = getattr(self.urlconf_module, "urlpatterns",
self.urlconf_module)
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in
_get_urlconf_module
274. self._urlconf_module =
import_module(self.urlconf_name)
File "/usr/lib/python2.7/dist-packages/django/utils/importlib.py" in
import_module
35. __import__(name)

Exception Type: ImportError at /admin/
Exception Value: No module named {{ project_name }}.urls

Gagan (GPS)

unread,
Jun 13, 2011, 7:56:39 AM6/13/11
to Django users
I seem to be getting this error for all pages. For a simple start page
the trace-back was:

Environment:


Request Method: GET
Request URL: http://192.168.2.127:8000/

Exception Value: No module named {{ project_name }}.urls


Daniel Roseman

unread,
Jun 13, 2011, 8:18:52 AM6/13/11
to django...@googlegroups.com
On Monday, June 13, 2011 11:56:18 AM UTC+1, Gagan (GPS) wrote:
I am having some difficulty accessing the admin of a project I am
trying to create.

My urls.py is the default with admin enabled:

from django.conf.urls.defaults import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', '{{ project_name }}.views.home', name='home'),
    # url(r'^{{ project_name }}/',
include('{{ project_name }}.foo.urls')),

    # Uncomment the admin/doc line below to enable admin
documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    url(r'^admin/', include(admin.site.urls)),
)

This is not the default admin. You seem for some reason to have put some template variable syntax in a Python file - I can't imagine why. Obviously, this is not valid Python syntax.
--
DR.

Gagan (GPS)

unread,
Jun 13, 2011, 8:25:40 AM6/13/11
to Django users
This is the urls.py with the admin bits uncommented from the default
urls.py file.

Gagan (GPS)

unread,
Jun 13, 2011, 8:36:53 AM6/13/11
to Django users
Also, A traceback of the error at /admin/ and /

Daniel Roseman

unread,
Jun 13, 2011, 9:14:17 AM6/13/11
to django...@googlegroups.com
On Monday, June 13, 2011 1:25:40 PM UTC+1, Gagan (GPS) wrote:
This is the urls.py with the admin bits uncommented from the default
urls.py file.

No it isn't. Somehow you have copied the skeleton urls.py from django/conf/project_template/. You should use django-admin.py startproject to set up your urls.py and settings.py correctly.

(Sorry, I mis-spoke on my last reply - it is valid Python, and the template syntax is from the skeleton version.)
--
DR.

christian.posta

unread,
Jun 13, 2011, 2:16:22 PM6/13/11
to Django users
Looks like you may have literally just uncommented the line without
replacing the {{project_name}} token with what your project name
really is. Did you use django-admin.py startproject to create the
project?
After doing so, use manage.py startapp <app_name> to create the app.
See the django tutorial for more:
https://docs.djangoproject.com/en/dev/intro/tutorial01/

GPS

unread,
Jun 13, 2011, 2:23:37 PM6/13/11
to django...@googlegroups.com
I was looking into how django works and had pulled the template files directly from the project_template directly and forgot to correct for the tag.

Based on what Daniel and Christian pointed out, I looked it up. Apparently I had a similar {{project_name}} tag in my settings.py file. That tag was creating the trouble as the settings were not redirecting the url handling to urls.py.

Even though the {{project_name}} tag is there in the urls.py, it is not affecting the working of the system as it is commented.

Thank you guys for the help.


Gagan Preet Singh


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


Reply all
Reply to author
Forward
0 new messages