Main content: Web framework, Django Foundation
Web Framework
Web Request Flow--Original web Framework--Customizing the web framework--MVC and MTV#Models views Controllers#function of template processing request#MVC#Models Templates views#function of template processing request#MTV#MTV#models: manipulating Databases#templates: templates, HTML#Views : Functions for processing requests
Django Basics
1, create the Django program A. Command Django-Admin startproject mysite Create project CD MySite python manage.py startapp app01 Create App01 Python manage.py startapp app02 create APP02 B. Pycharm Create Django Program Win: terminal, Python python manage.py startapp app01-Windows Mac:option+R Starapp app01 c. Directory Structure Project _name-project_name--->configuration file (settings.py)-manage.py-APP01-APP02-APP032, execute a Django program into Project Python manage.py runserver127.0.0.1:8000Click the Execute button above the Pycharm3, Django Dependent database configuration: Settings build database table: Python manage.py makemigrations#build configuration filePython manage.py Migrate#to create a database dependent on a configuration file4, admin python manage.py createsuperuser ... http:Localhost:8000/admin/5, routing system1, static routing2, dynamic routing according to the order, nth matching data, to the function of the nth parameter, strictly in accordance with the method of sequential matching template, the matching parameters are passed to the specified formal parameters3, level Two routing app01 url.py project_name url:app01Include ("App01.url") 6, basic Database Operations ORM Framework DB first create database tables and dictionaries yourself with commands-Create Class Code first write your own class-database tables Use classes to create database tables, and so on. A. Create Class B. Configure setttings.py Installed_apps= [ 'Django.contrib.admin', 'Django.contrib.auth', 'Django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'Django.contrib.staticfiles', "APP01",] B. Create a table from a class by using a command python manage.py makemigrations#build configuration filePython manage.py Migrate#to create a database dependent on a configuration fileC. default table name Appname_classname D. Views in import models E. Post submission Data settings operation:
# This is a temporary cancellation of cross-site request-related middleware middleware_classes= [ 'Django.middleware.security.SecurityMiddleware', 'Django.contrib.sessions.middleware.SessionMiddleware', 'Django.middleware.common.CommonMiddleware', #' Django.middleware.csrf.CsrfViewMiddleware ', 'Django.contrib.auth.middleware.AuthenticationMiddleware', 'Django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'Django.contrib.messages.middleware.MessageMiddleware', 'Django.middleware.clickjacking.XFrameOptionsMiddleware', ]
The path of Python Day15