Django基本知识

2018-09-24  本文已影响0人  Seinist

开发环境

Mac + python3

资料

https://docs.djangoproject.com/en/2.1/

项目初始化

django-admin startproject $project_name
python3 manage.py startapp $app_name
python3 manage.py runserver 0.0.0.0:$port
#1.一个project中包含若干个apps,每个app需要在project的目录下的settings.py中注册
#2.django的默认数据库是自带的

强大的 manage.py

1.manage.py会在新建项目后自动生成

python3 manage.py help
Type 'manage.py help <subcommand>' for help on a specific subcommand.

Available subcommands:

[auth]
    changepassword
    createsuperuser

[contenttypes]
    remove_stale_contenttypes

[django]
    check
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    makemigrations
    migrate
    sendtestemail
    shell
    showmigrations
    sqlflush
    sqlmigrate
    sqlsequencereset
    squashmigrations
    startapp
    startproject
    test
    testserver

[sessions]
    clearsessions

[staticfiles]
    collectstatic
    findstatic
    runserver

利用 manage.py shell 调试api

python3 manage.py shell
上一篇 下一篇

猜你喜欢

热点阅读