djangobook記錄

    最近學習了下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



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章