未使用{{useform}}而使用{{ userform.password }}形式便于后期css樣式
在澤州等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作按需開發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站制作,營銷型網(wǎng)站建設(shè),外貿(mào)網(wǎng)站制作,澤州網(wǎng)站建設(shè)費(fèi)用合理。<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="." method="POST">
{% csrf_token %}
<div>username: <input type="text" name="username"> </div>
<div>password: {{ userform.password }}</div>
<div><input type="submit" value="注冊" name="reg"> <input type="submit" value="登陸" name="login"> </div>
</form>
</body>
</html>
#/usr/bin/env python3
from django import forms
class UserForm(forms.Form):
username=forms.CharField()
password=forms.CharField()
from django.db import models
class User(models.Model):
username=models.CharField(max_length=30)
password=models.CharField(max_length=30)
def __str__(self):
return self.username
from django.shortcuts import render
from django.views.decorators.cache import cache_page
from .models import User
# Create your views here.
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from djapp.forms import UserForm
def user(request):
if request.method == 'POST':
userform=UserForm(request.POST)
if userform.is_valid():
if request.POST.get('reg'):
username=userform.cleaned_data['username']
password=userform.cleaned_data['password']
User.objects.create(username=username,password=password)
# user=User()
# user.username=username
# user.password=password
# user.save()
return HttpResponse("login 注冊%s"%username)
else:
if request.session.get('user_id') == 3:
return HttpResponse("session 登陸")
else:
try:
user=User.objects.get(username=request.POST.get('username',None))
except Exception as e:
print(e)
return HttpResponse("找不到用戶")
if user.password == request.POST.get('password'):
request.session['user_id']=user.id
return HttpResponse("登陸成功")
else:
return HttpResponse("登陸失敗")
else:
userform=UserForm()
return render(request,'djapp/user.html',{'userform':userform})
cookie保存sessionid
創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國云服務(wù)器,動(dòng)態(tài)BGP最優(yōu)骨干路由自動(dòng)選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡(luò)助力業(yè)務(wù)部署。公司持有工信部辦法的idc、isp許可證, 機(jī)房獨(dú)有T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確進(jìn)行流量調(diào)度,確保服務(wù)器高可用性。佳節(jié)活動(dòng)現(xiàn)已開啟,新人活動(dòng)云服務(wù)器買多久送多久。
本文名稱:pythondjango--簡單注冊/登陸/session-創(chuàng)新互聯(lián)
當(dāng)前網(wǎng)址:http://jinyejixie.com/article6/dhcdig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、服務(wù)器托管、自適應(yīng)網(wǎng)站、全網(wǎng)營銷推廣、網(wǎng)站導(dǎo)航、網(wǎng)站營銷
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容