不涉及数据库,简单实现登录功能
1.urls.py添加登录动作的路由。
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^index/', views.index),
url(r'^login_action/', views.login_action),
]
2.(结合前章内容已创建index.html页面)修改index.html页面,增加2个输入框和1个提交按钮。
注:①在表单内添加action跳转 action='/login_action/'
②{ {error}} 用来传错误提示 ③{% csrf_token %} csrf令牌(理解成是一个秘钥)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>管理系统</title>
</head>
<body>
<h1>登录管理系统</h1>
<form method="post" action="/login_action/">
<input name="username" type="text" placeholder="用户名" >
<input name="password" type