1

这里是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 新手)?请放轻松,给我注销功能的代码。

4

2 回答 2

1

我建议使用 Django 的内置身份验证功能,而不是推出自己的身份验证功能。否则,您一定会犯很多错误(例如存储纯文本密码,我认为这是您正在做的事情)并重新发明许多轮子(例如会话处理、组和权限等)。如果你需要存储比 Django 支持的更多的用户信息,你可以在表单或用户配置文件中完成。

无论如何,如果“登录”是指“在会话中拥有这些值”,“注销”你只需要删除它们,不是吗?

于 2013-02-07T13:27:39.077 回答
1

这真的很容易:

from django.contrib.auth import logout

def logout_page(request):
    logout(request)
    return HttpResponseRedirect('/')
于 2013-02-07T19:07:36.000 回答