Django 系列1:Django简介

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工程,就不会报数据库的错误。

posted @ 2020-01-19 18:41  xidianzxm  阅读(236)  评论(0编辑  收藏  举报