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

11👍

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

6👍

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

from django.contrib import admin
admin.autodiscover()

So it that particular block should look something like the following


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

# 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)),**

)

2👍

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

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

1👍

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 …

http://grokbase.com/p/gg/django-users/133v4wx0sx/django-1-5-tutorial-error-module-has-no-attribute-stackedinline

👤Josh

0👍

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

👤Rohan

0👍

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

👤Marat

0👍

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