1、Django MTV框架
MVC
MTV
2、安裝
虛擬環境
pip install Django==2.2.9
3、創建工程
django-admin startproject HelloDjango
python mange.py startapp App
er
python mange.py runserver
Django自帶內置了一個開發者服務器,性能比較低,上線以后不能用runserver
(venv) MacBookPro:HelloDjango zhangxm$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
January 21, 2020 - 06:16:24
Django version 2.2.9, using settings 'HelloDjango.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[21/Jan/2020 06:16:37] "GET / HTTP/1.1" 200 16348
[21/Jan/2020 06:16:37] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[21/Jan/2020 06:16:37] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876
[21/Jan/2020 06:16:37] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 86184
[21/Jan/2020 06:16:37] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692
Not Found: /favicon.ico
[21/Jan/2020 06:16:37] "GET /favicon.ico HTTP/1.1" 404 1977
4、pycharm 打開Django工程
打開目錄為manage.py父目錄文件夾, 然后配置虛擬環境解釋器
1)默認的解釋器
2)配置虛擬環境的解釋器
5、數據庫遷移
新建datasource并下載db drivers,Test Connection
python manage.py migrate
(venv) MacBookPro:HelloDjango zhangxm$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying auth.0010_alter_group_name_max_length... OK
Applying auth.0011_update_proxy_permissions... OK
Applying sessions.0001_initial... OK
(venv) MacBookPro:HelloDjango zhangxm$
這樣重新啟動python工程,就不會報數據庫的錯誤。