欢迎来到天天文库
浏览记录
ID:27870225
大小:188.00 KB
页数:9页
时间:2018-12-06
《基于Dragonboard 410c服务器系列之二局域网用户管理系统.doc》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、基于Dragonboard410c服务器系列之二局域网用户管理系统 在上一篇文章中,博主给大家分享了如何基于410c利用python的Django框架去构建自己的局域网web服务器,今天我们在其基础上再扩展建立一个局域网的用户管理系统。二、代码分析 1.代码框架 图1代码框架 2.主代码分享: 2.1.online/view.py#coding=utf-8fromdjango.shortcutsimportrender,render_to_responsefromdjango.httpimportHttpResponse,HttpRespon
2、seRedirectfromdjango.templateimportRequestContextfromdjangoimportformsfromonline.modelsimportUserfromdjango.contrib.authimportauthenTIcate,login#表单classUserForm(forms.Form):username=forms.CharField(label=‘用户名’,max_length=100)password=forms.CharField(label=‘密码’,widget=forms.Passwor
3、dInput())#defgetuser(forms):#returnforms.username#password1=forms.CharField(label=‘重复密码’,widget=forms.TexTInput())#loginaddr=“http://127.0.0.1:8000/online/login/”#registaddr=http://127.0.0.1:8000/online/regist/#注册defregist(req):ifreq.method==‘POST’:uf=UserForm(req.POST)ifuf.is_val
4、id():#获得表单数据username=uf.cleaned_data[‘username’]password=uf.cleaned_data[‘password’]password1=req.POST[‘password1’]#比较数据库中是否已有用户#user=myUser.objects.all().filter(username=username)#print(user)ifUser.objects.filter(username=username).exists():returnrender_to_response(‘registfaild.h
5、tml’,{‘uf’:uf},context_instance=RequestContext(req))else:ifpassword1==password:#User.objects.create(username=username,password=password)#添加用户进数据库#profile=UserProfile()#e*************************#profile.user_id=user.id#profile.phone=phone#profile.save()#user=User()#user.username=u
6、sername#user.password=password#user.save()user=User.objects.create_user(username,password)user.save()response=HttpResponseRedirect(‘/online/registsuccee/’)returnresponseelse:returnrender_to_response(‘registfaild1.html’,{‘uf’:uf},context_instance=RequestContext(req))else:uf=UserFor
7、m()returnrender_to_response(‘regist.html’,{‘uf’:uf},context_instance=RequestContext(req))#登陆deflogin(req):#getAllUser(req)ifreq.method==‘POST’:uf=UserForm(req.POST)ifuf.is_valid():#获取表单用户密码username=uf.cleaned_data[‘username’]password=uf.cleaned_data[‘password’]#获取的表单数据与数据库进行比较user
8、=authenTIcate(username=username,p
此文档下载收益归作者所有