尝试使用视图中所需的django大括号登录mixin 我没有用于存储会话的数据库我正在使用
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
当我输入网址时,没有登录(例如:8000 /仪表板,它指示我登录) 但是当我尝试登录时,并没有将我重定向到我的仪表板页面
请帮助
class Login(CsrfExemptMixin, View):
template_name = 'login.html'
def get(self, request, *args, **kwargs):
try:
if request.session['access_token']:
if request.session['path_previous']:
return HttpResponseRedirect(request.session['path_previous'])
else:
return HttpResponseRedirect('/dashboard/')
except:
return render_to_response( self.template_name, context_instance=RequestContext(request))
def post(self, request, *args, **kwargs):
username = request.POST.get('uName','')
password = request.POST.get('pwd','')
login_obj = LoginDataView()
login_response = login_obj.get(request,username,password)
if login_response.status_code == 200:
request.session['access_token'] = login_response.json()['access_token']
request.session.set_expiry(10000)
print "hihihihihi"
return HttpResponseRedirect('/dashboard/')
else:
context = {
'bad_string' : "Please provide correct login credentials",
}
return render_to_response( self.template_name, context, context_instance=RequestContext(request))
class GetDashboardView(LoginRequiredMixin,CsrfExemptMixin, View):
login_url = '/login/'
#redirect_field_name = "hollaback"
raise_exception = False
template_name = 'index.html'
def get(self, request, *args, **kwargs):
tpl = tpl_lookup.get_template(self.template_name)
#return render_to_response( self.template_name, context_instance=RequestContext(request))
return HttpResponse(tpl.render())
答案 0 :(得分:0)
尝试使用django-registration左右。如果您将使用它添加到您的urls.py:
url(r'^accounts/register$', RegistrationView.as_view(form_class=
RegistrationFormUniqueEmail), name='registration_register'),
url(r'^accounts/', include('registration.backends.default.urls')),
url(r'^accounts/', include('django.contrib.auth.urls')),
registration.backends.default.urls
包含损坏的名称,因此包括django.contrib.auth.urls
修复它。
如果您将使用gjango-social-auth,请在urls.py中添加以下行
url(r'^accounts/', include('social_auth.urls')),
并通过在settings.py
中添加以下行来修复datatime JSON序列化SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
这不是完整的教程等等,它只是一些出路。