美文网首页
django 笔记

django 笔记

作者: 42chaos | 来源:发表于2018-04-03 17:47 被阅读1次

    model.py

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

    setting.py加入config

    INSTALLED_APPS = [
        'polls.apps.PollsConfig',
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
    ]
    

    创建数据库表结构

    $ python3 manage.py makemigrations polls
    

    django的shell

    python3 manage.py shell
    

    相关文章

      网友评论

          本文标题:django 笔记

          本文链接:https://www.haomeiwen.com/subject/otfchftx.html