Django主线

Django怎么学:

参考地址:https://www.zhihu.com/question/26235428

需要了解的知识点:

Django Url请求流程

首要操作

Django的安装

pip3 install django

默认安装在Python36安装目录下的Scripts目录下:

C:\Users\admin\AppData\Local\Programs\Python\Python36\Scripts
	可执行文件:django-admin
	默认是加入环境变量中的;

项目解析:

    整体项目为             project  mysite
    	包含配置文件
    	管理文件
    
    项目内部每个模块为     app 		app01-cmdb (处理业务逻辑)
								    app02-监控

创建项目project:

django-admin startproject mysite

创建APP:

cd mysite
python manage.py startapp cmdb		    # 创建cmdb app项目
python manage.py startapp monitor		# 创建aws  app项目

1 .创建完成项目后,启动项目:

C:\aws>python .\manage.py runserver 127.0.0.1:8000

2 .将环境依赖的 模块导出

C:\aws>pip freeze > requirements.txt

3 .将环境依赖的 模块导入

C:\aws>pip install -r requirements.txt

4 .初始化数据库

C:\aws>python .\manage.py makemigrations
No changes detected

5 .创建数据库,默认使用sqlite3数据库,如果使用MySQL数据库,需要在settings里面指定数据库配置

C:\aws>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 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 sessions.0001_initial... OK

6 .创建admin管理用户

C:\aws>python .\manage.py createsuperuser
Username (leave blank to use 'admin'): admin
Email address:admin
Password:admin123
Password (again):admin@123
Superuser created successfully.
posted @ 2017-09-13 18:12  叨客厨子  阅读(327)  评论(0编辑  收藏  举报