使用eclipse +django1.9+python2.7學習環境html
在寫完models和views以後,須要同步數據庫python
django1.9以後的再也不使用sysdb的命令使用數據庫
1.manage.py migrate來初始化數據的基本表django
2.使用 manage.py creaetsuperuser建立一個超級用戶管理員eclipse
3.使用 manage.py makemigrations 模塊(model) ,建立對應的表python2.7
models的建立post
class BlogPost(models.Model): title = models.CharField(max_length = 150) content = models.TextField() timestamp = models.DateTimeField() class BlogPostAdmin(admin.ModelAdmin): list_display = ('title', 'content', 'timestamp') admin.site.register(BlogPost, BlogPostAdmin)
views.py學習
from django.template import loader,Context from django.http import HttpResponse from blog.models import BlogPost # Create your views here. def archive(request): posts =BlogPost.objects.all() t = loader.get_template('archive.html') c = Context({'posts': posts}) return HttpResponse(t.render(c))