以下是views.py
:
def authent(request):
user = request.POST['username']
passw = request.POST['password']
featureDetail = []
loginrole = People_Login.objects.get(User_Name = user, Password = passw)
features = Role_FGroup_FSubGroup_FItems_Map.objects.filter(Role_Id = loginrole.id)
for p in features:
dic = {}
dic['ID'] = p.id
dic['Role_ID'] = p.Role_Id.id
dic['FGID'] = p.Feature_Group_Id.id
dic['FSGID'] = p.Feature_SubGroup_Id.id
dic['FIID'] = p.Feature_Items_Id.id
dic['SFGNAME'] = p.Feature_Group_Id.Name
dic['SFSGNAME'] = p.Feature_SubGroup_Id.Name
dic['SFINAME'] = p.Feature_Items_Id.Name
featureDetail.append(dic)
featuresgroups = Role_Feature_Group_Map.objects.filter(Role_Id = loginrole.Role_Id.id)
request.session['feature_list'] = featureDetail
request.session['featuresgroups'] = featuresgroups
return render_to_response('UAM/index.html',{"contacts":featureDetail,'len':len(featureDetail)-1,'test1':"shiva",'test2':"shiva","featuresgroups":featuresgroups})
对于这个authent
函数,如何编写我的注销函数
(因为我是Django的新手)?请轻松告诉我注销功能的代码。
答案 0 :(得分:1)
我建议使用Django的built in authentication features而不是推出自己的。否则,你肯定会犯很多错误(例如storing plain text passwords,我看到你正在做的事情)并重新发明许多轮子(例如会话处理,组和权限等)。如果您需要存储有关用户的更多信息而不是Django支持,您可以在表单或user profiles中进行。
无论如何,如果“登录”你的意思是“在会话中拥有这些值”,要“退出”你只需要删除它们,不是吗?
答案 1 :(得分:1)
这真的很容易:
from django.contrib.auth import logout
def logout_page(request):
logout(request)
return HttpResponseRedirect('/')