有一段时间没研究django了,现在要用django做一个网站,于是重新翻了一下django的官方的tutorial,总结了一下创建app以及使用admin的步骤(假设project名为mysite,app名为pools)。
start app with database
1.“django-admin.py startproject mysite”
2.“manage.py startapp polls”
3.create the model by edit models.py
4.add the database support by modify setting.py (DATABASES)
5.add the polls app to the project by modify setting.py(INSTALLED_APPS)
6.“manage.py sql pools”(“manage.py validate”) not a nessesary step
7.“manage.py syncdb”
using admin
1.add "django.contrib.admin" to setting.py(INSTALLED_APPS)
2."manage.py syncdb"
3.edit mysite/urls.py (uncomment the three lines about “admin”)
4.create admin.py in the polls directory, edit it like this:
5.restart the server
然后就可以通过localhost:8000/admin来访问了