django framework basis - long-term maintenance -20,191,212

django framework basis:

 

Learning ############### django framework ################

Learning methods:
 1 , with their main memory
 2 , combined with analysis of the project, to be the most critical,
 3 , blog summary manner
 4, must understand the principles

 

############### MVC architecture introduced ################

# MVC architecture 
# a software framework has a lot of modules, each module has different functions 
# mutual cooperation between the module and the module to complete the software development, 
# Django follows the MVC framework for thinking 
# generate MVC concept: the division of labor. Is to let a special person to do something special, 
# core of MVC is: decoupling, that is, between a module and other modules but with little relevance, as long as you upgrade a module to complete the function, little effect on other modules 
# M: model, models, databases, and interact 
# V: view, view, generates html page 
# C: controller, controller, receives the request, processes, 
# ############## ####################### 
# illustration, MVC is how the work of three of 
# browser, the time of registration, submit a user name and password 
# C: the controller, receiving data, processing, and interacts with the V M 
# C does not save their data to the database directly, by M saving the user name and password to the database, and then returns to the get data C M after, 
# if desired generate pages, C does not generate its own home page, it generates HTML pages through V, and V html page to return to C, 
# Finally C, and the data is returned to the browser html page

 

############### django framework -MVT ################

# Django framework 
# Django is a python inside a follow an MVC framework, but he has his own name, called MVT, but still follow a thought MVC division in nature 
# M: Model, model, and M functions in MVC as is, and data interaction, 
# V: view, view, and C functions in MVC, as reception data, processes, and M and T interaction, and return data, 
# T: Templates, model, and MVC Like the V function is to generate HTML pages, 
# example: 
# browser, user registration, submit your username and password 
# this django no C, then how to run, is to receive data through the view, 
# by M data saved to the database, and then return to the view V, 
# then V is not generated html page, and is used to generate HTML pages by T templates, and then handed over to the view V, 
# finally V data and pages returned to the browser, 
# ################### 
# Django documentation must see more: https://yiyibooks.cn/xx/Django_1.11.6/index.html

 

############### django installation, project creation, app create a configuration, project start-################

# The first is to install Django: 
# enter Terminal pycharm in, or enter cmd, the 
PIP install Django == 1.11.11 -i https://pypi.tuna.tsinghua.edu.cn/ the Simple
Django - ADMIN   # continue to enter after installing Django - admin, appeared content to the installation was successful 
Python Django --version -m   # continue to enter, you can achieve the look Django version

# Create the first Django project: 
# The first: You can use pycharm create, create a project when selecting Django, 
# second: command to create, 
# first project where you want to create a directory, then enter the directory, Run: 
Django-ADMIN startproject test1 # (project name)

# Project directory analysis: 
manage.py   # project management file, the file can be managed through this entire django project 
test1
     __init__ .py # represents test1 This is a python package 
    settings.py # configuration items 
    url.py # routing configuration 
    wsgi .py   # one entrance web server and interact with django


# Create an application: 
Python manage.py startapp App name
 # file directory analysis 
admin.py # this website and back office management of related files 
__init__ .py
migirations
    __init__.py
model.py # database-related content 
views.py   # accept the request, sort, and M and T interact 
test.py # write test code file 
# also need to apply to register: 
# the settings of INSTALLED_APPS, plus app name

# Start the service, in the cmd first enter the project path, or in the terminal in pytcharm 
# execute the command: 
Python manage.py the runserver
 # or click the Run button to start directly in pycharm in

 

############### ORM introduction and use mysql basic configuration ################

# ORM Profile 
# O is the object, the object 
# R is a relation, relationship, which is a relational database table 
# M is a mapping, mapping 
# in django which is mainly in models.py file inside design model class, 
# #### ###################### 
# ORM another role: according to generate database design class in table 
# Django ORM is used to create a table 
# this can be used to write Python statements, and then automatically translated into sql statement, but this great God wrote the efficiency and execution of sql programmer writing there are still gaps, 
# class - data sheet 
# objects - data rows 
# attributes - fields, sort these three points, ORM is no problem

# Configured to use the database mysql 
# Step: In the Project Directory - -settings project file folder, 
DATABASES = {
     ' default ' : {
         ' ENGINE ' : ' django.db.backends.mysql ' ,
         ' NAME ' : ' XXX ' ,
         ' the USER ' : ' the root ' ,
         ' PASSWORD ' : ' XXX ' ,
         ' the HOST ' : 'localhost',
        'PORT':3306,
    }
}
# Step Two: In the project directory - the project folder -__ init__ file, 
Import pymysql
pymysql.install_as_MySQLdb()

# Create a database 
# ORM can manipulate data tables, manipulate rows, but can not create a database, you need to create your own database, which is the case of using the mysql 
# If you're using SQLite, you do not need to create anything beforehand - the database file will created automatically when needed. 
cmd
mysql -uroot -p
create database XXXXX;
use django
show tables;

 

Learning ############### django framework ################

 

 

Learning ############### django framework ################

 

 

Learning ############### django framework ################

 

 

 

 

Learning ############### django framework ################

 

 

Learning ############### django framework ################

 

Learning ############### django framework ################

 

 

############### end line ################

 

 

 

 

Guess you like

Origin www.cnblogs.com/andy0816/p/12029122.html