Python's most functional web framework: Django, the framework itself integrates ORM, model binding, template engine, caching, session, and many more.
The following actions are required to use Django:
1. There are two ways to create a Django project.
A, command operation:
Django-admin startproject dg_web//dg_web for project name
B. Create a new Django project directly under the IDE of the development environment
The file directory after the project was created is as follows:
2, the creation of the project under the establishment of a functional program, the operation is as follows:
Command line: Python manage.py startapp app01//Create function program APP01, create multiple then replace APP01 with new program
3, initialize the database, Django itself admin uses the data for Sqlite3, initialize the database command steps are as follows:
A, Python manage.py makemigrations//Generate config file
B, Python manage.py migrate//Generate database-related content based on configuration files
4, if APP01 need to create their own database tables, you need to first create a table in the models file class, and then perform the 3rd step operation.
A, example: Models file to add a user information class:
from Import Models # Create your models here. class UserInfo (models. Model): = models. Charfield (max_length=16) #建立username字段 = models. Charfield (max_length=16) #建立password字段 = models. Integerfield () #建立age字段
b, in the Global configuration file Settings add App01 as the location:
C, the implementation of the 3rd step:
I, Python manage.py makemigrations//Generate config file, create 0001_initial.py file
II, Python manage.py migrate//based on the configuration file to generate database-related content, you can use the tool connection Sqlite3 view the new UserInfo table information,
django[Basic Knowledge]