Advanced Python: What django framework is Day1, how to use it, and where is it used?

Preface: django framework

Hello everyone, I am Latiao and haven't updated high-energy works for a long time. From today onwards, I will update series of works irregularly, which may be biased towards intermediate and advanced levels. Students who have no foundation can read my previous basic blog posts~ Or directly through At the end of the article, find the spicy strips directly on the business card~

Without further ado, let's start directly

Django is an open source web application framework written in Python. The framework pattern of MTV is adopted, that is, model M, view V and template T. It was originally developed to manage some news content-based websites under the Lawrence Publishing Group, that is, CMS (Content Management System) software. and released under the BSD license in July 2005. This frame is named after Belgian gypsy jazz guitarist Django Reinhardt.

insert image description here

1. web application

Web application: It is an application program that can be accessed through the web. The biggest advantage is that the user can easily access the application program. The user only needs to open the web page in the browser and does not need to install other software.
cs architecture
web application: Most of them are programs based on b/s architecture.

Advantages of web applications

1. Only need a browser.
2. Web applications typically consume very little space on the user's hard drive.
3. Does not need to be updated, all features are executed on the server, thus automatically communicated to the client
4. It is easy to combine with server-side network products, such as email function and search function
5. Because it runs in the web browser window, So in most cases it can be used across platforms

Disadvantages of web applications

1. Special emphasis on the applicability of the browser
2. If there is a problem with the connection, the application will not be accessible
3. Cannot be customized and personalized for users
4. In theory, any user's behavior can be retrieved, which may bring privacy and security issues

Summarize

Essentially: the browser is a socket client, and the server is a socket server

2. http protocol

what is http protocol

The http protocol is a hypertext transfer protocol , which
is an object-oriented protocol belonging to the application layer
. As the client of http, the browser sends all requests to the web server through the url, and the web server sends a response message to the client after receiving the request.

Features of the http protocol

1. Application layer protocol based on tcp (transport layer)/ip (network layer) protocol
2. Based on request and response mode The
protocol stipulates that the request is sent from the client, and finally the server responds to the request and returns
3. No state preservation: The http protocol itself does not save the communication state between the request and the response, that is to say, the http protocol does not perform persistent processing on the request and sending.
Note:
Since http has no state saving, cookie technology is introduced for persistent processing. With cookies Then use the http protocol to communicate, and then you can manage the state.
4. No connection: The meaning of no connection is to limit each connection to only process one request. After the server finishes processing the client's request and receives the client's response, it disconnects. In this way, transmission time can be saved.

http request protocol and response protocol

http请求协议:
请求首行:
post(请求方式:POST/GET) /form/index HTTP/1.1
请求首部字段(请求头):
Host:127.0.0.1
Connection:keep-alive
Content-Type:application/x-www-form-urlencoded
Content-Length:16
请求体:
name = ueno&age = 33
请求方式:get与post请求
1.GET提交的数据会放在url之后,以?分割url和传输数据,参数之间以&相连,如?name = test1&id = 1。
POST方法是把提交的数据放在http包的请求体中。

2.GET提交的数据大小有限制(因为浏览器的url的长度有限制),而POST方法提交的数据没有限制。

3.GET与POST请求在服务端获取请求数据方式不同

response protocol


状态行:协议版本 状态码 状态码描述 
HTTP/1.1 200 OK

响应头部:
头部字段名:值 \r\n

响应正文:

response status code

| Status Code | Category | Reason Phrase |
| ——
|
| The request has been processed normally|
| 3xx | Redirection status code| Nearby operations are required to complete the request|
| 4xx | Client error status code| The server cannot process the request|
| 5xx | Server error status code|

Introduction to url

统一资源定位符是对可以从互联网上得到的资源的位置和访问方法的一种简洁的表示,是互联网上标准支援你的地址。互联网上标准资源的地址,互联网上的每个文件都有一个唯一的url,它包含的信息支出文件的位置以及浏览器应该怎么处理它

格式:
协议://ip:端口(80) /路径?name=lqz$age=age=18

?之前的是请求路径,?之后的是请求数据部分

3. The mainstream web framework (MVC) in python

clipboard
clipboard1
clipboard2

a:socket b:路由和视图匹配关系 c:模板渲染

django: a:用了wsgiref b:自己 c:自己
flask: a:用了别人的 b:自己 c:jinja2
tornado:a:自己 b:自己 c:自己

img
img
img
img
img
img
img

4. General summary

insert image description here
img
img

django install

1. Several parts

img
ig
img
img
img
img

Can have multiple apps

img
img
ig

Precautions

ig
ig

command run django

mg
mg
ig

django install

下载django
1.pip install django==1.11.9 

创建项目
2.django-admin startproject 项目名 

创建app
3.python manage.py startapp app01

运行项目
4.python mansge.py runserver 127.0.0.1:8001

django file directory

anage.py   项目的入口,执行一些命令
settings    全局配置信息
urls        总路由,请求地址和视图函数的映射关系
migrations  数据库迁移的记录
models      数据库表模型
views       视图函数

↓↓↓↓↓↓Latiao business card through train↓↓↓↓↓↓

Guess you like

Origin blog.csdn.net/AI19970205/article/details/128123334