Hick
Hick

Reputation: 36394

NameError:Admin not found in django

The urls.py of the project is this

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

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

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

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

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
    (r'', include('Sdr.sdr.urls')),
)

The urls.py of the app looks like this

# Import django modules
from django.conf.urls.defaults import *
from django.contrib import admin
# Import custom modules
import settings


admin.autodiscover()
urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    (r'', include('Sdr.sdr.urls')),
)

The error I am getting is exception found is

Django Version: 1.3
Exception Type: NameError
Exception Value:    
name 'admin' is not defined

Upvotes: 15

Views: 9401

Answers (3)

Max Elahov
Max Elahov

Reputation: 221

Faced with the same problem in tutorial. Try to add in models.py:

from django.contrib import admin

Upvotes: 8

Amazing Angelo
Amazing Angelo

Reputation: 1728

Uncomment the following in your project's urls.py.

from django.contrib import admin

admin.autodiscover()

Upvotes: 9

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798526

You forgot to import admin in the project's urls.py. Read harder.

Upvotes: 25

Related Questions