首页 > 代码库 > Django官方文档学习2——数据库及模板

Django官方文档学习2——数据库及模板

网址:https://docs.djangoproject.com/en/1.10/intro/tutorial02/

 

1.扫描installed_apps,创建需要的数据库table

python manage.py migrate

2.在APP中创建模板(models)

from django.db import modelsclass Question(models.Model):    question_text = models.CharField(max_length=200)    pub_date = models.DateTimeField(date published)class Choice(models.Model):    question = models.ForeignKey(Question, on_delete=models.CASCADE)    choice_text = models.CharField(max_length=200)    votes = models.IntegerField(default=0)

3.安装一个app

# mysite/settings.pyINSTALLED_APPS = [    polls.apps.PollsConfig,...

4.对于model做出的变化更新

python manage.py makemigrations polls

python manage.py migrate

 

Django官方文档学习2——数据库及模板