python專案 Django請求流程

2021-09-11 02:57:51 字數 767 閱讀 7367

1、瀏覽器傳送請求request給web伺服器;

2、web伺服器將請求**給django框架處理;

(django接收到第乙個請求,會呼叫中介軟體的__init__方法,完成中介軟體的初始化)

3、處理請求前呼叫proces_request(request),返回none或httpresponse物件;

4、通過urlconf匹配,確認請求由哪個檢視處理;

5、process_view(request,view_func,view_args,view_kwargs)在處理檢視前呼叫,返回none或httpresponse物件;

6、檢視接收到resquest;

(1) 通過模型model與資料庫互動,獲取並處理資料,model內嵌orm框架,實現物件導向來運算元據庫;

(2) 模板引擎,實現動態展示資料,返回httpresponse物件或者jsonresponse物件。

7、檢視處理響應後返回response,所有的response(包括process_request和process_view返回的response)在返回給django前都會呼叫process_response(request,response),返回httpresponse物件,除非做了特殊處理。

(如果檢視丟擲異常,在每個請求上呼叫precess_exception(request,exception),返回none或httpresponse物件。

Python建立Django專案

1.django的安裝 1 用pip來安裝 若未安裝pip,看第1 步,否則直接看第2 步 2 利用pip安裝django pip install django 或者 pip install django 2.0.4 公升級pip可以用 pip install upgrade pip 2.djang...

python建立django專案報錯

python37 django3.0.7configured.you must either define the environment variable django settings module or call settings.configure before accessing sett...

python框架之Django專案建立

目錄 1.django專案建立命令 2.django專案setting設定 1 類名設定 2 資料庫模組設定 3 其他設定 3.django資料庫連線 4.django專案利用model模組直接建立資料表 5.django專案執行命令 建立虛擬環境,切換到虛擬環境,執行以下命令 django adm...