最近学习了下django,准备自己搭建一个共同学习医学的网站,认真读了最著名的djangobook
http://www.djangobook.com我装的1.6,他讲的是1.4,中间遇到了几个问题,在这里记录一下,如果有同学也遇到可以参考一下.
再看chapter06.html 这是第六章,做后台的时候,注意这么一段话:
Make sure MIDDLEWARE_CLASSES contains‘django.middleware.common.CommonMiddleware‘,‘django.contrib.messages.middleware.MessageMiddleware‘,‘django.contrib.sessions.middleware.SessionMiddleware‘ and‘django.contrib.auth.middleware.AuthenticationMiddleware‘. (Again,
if you’re following along, note that we commented them out in Chapter 5,
so uncomment them.)
这段话说明完成后台时MIDDLEWARE_CLASSES需要包含的类,注意, 包含的时候,the SessionMiddleware must before MessageMiddleware!!!,session的类一定要在message之前,先后加载一定不能反,否则就会报错,不能按书上的顺序.
再往下看有这莫一段:
Adding Your Models to the Admin Site
Within the books directory (mysite/books), create a file calledadmin.py, and type in the following lines of code:
from django.contrib import admin admin.site.register(Publisher) admin.site.register(Author) admin.site.register(Book) 这段之中,加粗的import可能会出现问题,如果books里面的类和admin.py在同一文件夹下,直接 from mysite.books.models 改为from models就可以导入类,不然需要sys.path.append,根据书上会报错,这是一个ImportError问题,具体见 http://my.oschina.net/leejun2005/blog/109679