流程:
1、浏覽器通路http://127.0.0.1:8002/user/login/
2、urls.py中 path('login/', views.login, name="login"),執行views下的login函數
3、URL 請求為GET,跳轉到 return render(request,'user/login.html')

4、輸入使用者名,密碼,點選表單送出後,通過<form action="{% url 'user:login' %}" method="POST"> 到user(app_name) 的login(name)
5、執行path('login/', views.login, name="login") 的login函數
django 設定 session 過期時間:
session 設定
SESSION_COOKIE_AGE = 60 * 30 # 30分鐘
SESSION_SAVE_EVERY_REQUEST = True
SESSION_EXPIRE_AT_BROWSER_CLOSE = True # 關閉浏覽器,則COOKIE失效
流程
顯示頁面流程
建立的app為user(使用者管理),以下配置都在user下操作
1、确定通路的url位址 /user/index
2、urls.py(路由)
path('index/', views.index, name="index"),
第一個參數'index/' :路由的名稱
第二個參數views.index :表示url跳到/user/index後 執行views檔案中的index方法
第三個參數name="index":表示指定該方法的名稱為index,比如需要跳轉到這個路徑下就可以用user:index
3、編輯views.py 下的index函數
取到資料後,傳回資料
request的參數是必須要的,因為要接受浏覽器上傳遞過來的參數
return render(request, 'user/index.html', {
'users' : users.items()
})
render 渲染html,傳入變量 users的值,index.html可以周遊引用
POST請求