[PYTHON] DJango memo: From the beginning (using the management screen) my addictive point

Entering Tutorial 2 from this time http://www.djangoproject.jp/doc/ja/1.0/intro/tutorial02.html#intro-tutorial02

By the way, I'm not addicted to it anymore, but I dare to leave it as it was at that time.

By the way, in my environment, python is 2.7.5 and DJango is 1.6.

Use admin page

First check settings.py

settings.py ######

#this part
INSTALLED_APPS = (
     'django.contrib.admin',   #I need this. In my case it was included by default
     'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
     'django.contrib.sites',
     'polls'
 )

If you add it again

python manage.py syncdb

Execute. It's a theory to add a database after adding an application. Then edit urls.py. I got a little troubled here.

urls.py ###### In the tutorial

from django.conf.urls.defaults import *

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Example:
    # (r'^mysite/', include('mysite.foo.urls')),

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

    # Uncomment the next line to enable the admin:
    (r'^admin/(.*)', admin.site.root),
)

Since it is described as such, for the time being, just do it

python manage.py runserver

After this, if you go to http://127.0.0.1:8000/admin/, you should see the login screen. But the result is an error. The message is

ImportError at /admin/

No module named defaults

I think it may be due to the difference in version (the tutorial assumes 1.0, but I am 1.6), so I will return to the state before editing. Actually, there was the following description before editing.

from django.conf.urls import patterns, include, url   #Import statement included by default
 
from django.contrib import admin
admin.autodiscover()
 
urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'myDj.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),   #All examples()Is preceded by a url
)

Since what I'm doing looks the same, I thought that the writing style had changed, so I started it and accessed it. But again, no. However, the error message is different.

ImproperlyConfigured at /admin/

You're using the Django "sites framework" without having set the SITE_ID setting. Create a site in your database and set the SITE_ID setting to fix this error.

I don `t really understand. It's understandable that you are told to set a site ID, but how do you do that? Even if I googled with an error message

This time I tried to write in a timely manner as a measure of bitterness.

from django.conf.urls import patterns, include, url   #Adopt the one that does not fail here

from django.contrib import admin
admin.autodiscover()
 
urlpatterns = patterns('',
    #Default notation url(r'^admin/', include(admin.site.urls))
    #Tutorial notation(r'^admin/(.*)', admin.site.root)
    url(r'^admin/(.*)', include(admin.site.root))

Then

AttributeError at /admin/

'AdminSite' object has no attribute 'root'

The above is the contents at that time.

Now it's resolved thanks to the comments (I'm glad I posted it).

Recommended Posts

DJango memo: From the beginning (using the management screen) my addictive point
DJango Memo: From the beginning (more edits to the management screen)
DJango Memo: From the beginning (Error screen settings)
DJango memo: From the beginning (editing the management screen) There is a mystery
DJango Memo: From the beginning (preparation)
DJango Memo: From the beginning (model settings)
DJango Memo: From the beginning (creating a view)
DJango Note: From the beginning (using a generic view)
DJango Note: From the beginning (form processing)
Django memo # 1 from scratch
DJango Note: From the beginning (creating a view from a template)
Django page released on heroku: Preparation my addictive point
Study from the beginning of Python Hour8: Using packages
[Django] Correct the plural form of the model name on the management screen
Django admin screen reverse lookup memo
Get the value from the [Django] Form
Throw GQL with a numeric ID from the App Engine management screen
Organize the flow when running Django using NGINX and gunicorn (personal memo)
Get news from three major mobile companies using Django and the News API
How to build an application from the cloud using the Django web framework