Django 请求和响应学习 views:
def login(request):
if request.method == 'GET':
return render(request,'login.html')
else:
print(request.POST)
username = request.POST.get('user')
password = request.POST.get('pwd')
if username == 'root' and password == '123':
return redirect("https://www.csdn.net/")
else:
return render(request,'login.html',{'error_message':'用户名或密码错误'})
login.html:
<h1>用户登录</h1>
#列表
<form method="POST" action="/login/">
{% csrf_token %}
<input type="text" name="user" placeholder="用户名">
<input type="password" name="pwd" placeholder="密码">
<input type="submit" value="提交">
<span style="color:red">{{ error_message }}</span>
以上内容为跟着视频学习过程中所记笔记。
|