[Fixed]-Python Error: name 'admin' is not defined


from django.config import admin should be from django.contrib import admin


at the top of your **url.py** file, add the following code

from django.contrib import admin

So it that particular block should look something like the following

from django.conf.urls import patterns, include, url
**from django.contrib import admin

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

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'examplesite.views.home', name='home'),
    # url(r'^examplesite/', include('examplesite.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)),**



i change my urls.py like this… this should be the basic format

from django.conf.urls import  include, url
from django.contrib import admin

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


Well after an long, agonizing quest to fix this stupid problem, I FINALLY came across the answer! Another Django programmer ran into the same problem and found this:

IN THE PARENT OF ChoiceInLine (which you’ll see as ‘admin.StackedInline’ in the tutorial), THE L IN StackedInline SHOULD NOT BE CAPITALIZED … It’s as simple as that … thankyou SO much Karen Tracey …




I suspect you don’t have from django.contrib import admin in your model file where you defined ModelAdmin classes, class ChoiceInline(admin.StackedInline):.



You should place the admin code (everything after #COMMENTED OUT UNTIL I FIX THE ADMIN NAME) to admin.py



A way to fix this for me was to add this in the beginning of admin.py:

from django.contrib import admin

Leave a comment