美文网首页
django入门基础指令

django入门基础指令

作者: quchangTJU | 来源:发表于2019-07-25 16:51 被阅读0次

    安装django指令

    pip install Django
    

    新建项目(名称为mysite)

    django-admin startproject mysite
    

    运行django项目

    python manage.py runserver
    python manage.py runserver 0.0.0.0:8000
    

    创建应用(名称为polls)

    python manage.py startapp polls
    

    为应用生成数据库(以polls为例)

    python manage.py makemigrations polls
    python manage.py migrate
    

    创建管理员账户

    python manage.py creatsuperuser
    

    QuerySet检索常用函数

    #获取所有Entry对象
    all_entries = Entry.objects.all()
    #获取pub_date__year=2006的Entry对象
    Entry.objects.filter(pub_date__year=2006)
    Entry.objects.all().filter(pub_date__year=2006)
    #保存对象
    a.save()
    #get检索单个对象
    one_entry = Entry.objects.get(pk=1)
    #获取Question对象中question_text以What为开头的对象
    Queation.Objects.filter(question_text__startswith='what')
    

    相关文章

      网友评论

          本文标题:django入门基础指令

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