def login(request):
if request.method == 'POST':
uf = LoginForm(request.POST)
if uf.is_valid():
#獲取表單用戶密碼
username = uf.cleaned_data['name']
password = uf.cleaned_data['pwd']
#獲取的表單數據與數據庫進行比較
return HttpResponseRedirect('/homepage/')
else:
uf = LoginForm()
return render_to_response('l.html',{'uf':uf},context_instance=RequestContext(request))
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>登錄</title>
</head>
<style type="text/css">
body{color:#efd;background:#453;padding:0 5em;margin:0}
h1{padding:2em 1em;background:#675}
h2{color:#bf8;border-top:1px dotted #fff;margin-top:2em}
p{margin:1em 0}
</style>
<body>
<h1>登錄頁面:</h1>
<form method = 'post' enctype="multipart/form-data">
{% csrf_token %}
{{uf.as_p}}
<input type="submit" value = "ok" />
</form>
</body>
</html>