当我尝试在我的仪表板中登录时,Django 1.10会出错。
追踪(最近一次呼叫最后一次):
File "/Users/guest/epifiction/lib/python2.7/site-packages/django/core/handlers/exception.py", line 39, in inner
response = get_response(request)
File "/Users/guest/epifiction/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/guest/epifiction/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/guest/epifiction/lib/python2.7/site-packages/django/views/decorators/cache.py", line 58, in _wrapped_view_func
add_never_cache_headers(response)
File "/Users/guest/epifiction/lib/python2.7/site-packages/django/utils/cache.py", line 230, in add_never_cache_headers
patch_response_headers(response, cache_timeout=-1)
File "/Users/guest/epifiction/lib/python2.7/site-packages/django/utils/cache.py", line 219, in patch_response_headers
if not response.has_header('Last-Modified'):
AttributeError:' NoneType'对象没有属性' has_header'
这是查看代码
class AuthorLoginView(bracesviews.AnonymousRequiredMixin,authviews.LoginView):
form_class = forms.AuthorLoginForm
template_name = 'landing_page/demo.html'
def form_valid(self, form):
username = form.cleaned_data.get('username')
userId = User.objects.get(username=username).id
try:
profile_obj = UserProfile.objects.get(user_id=userId)
except UserProfile.DoesNotExist:
return super(AuthorLoginView, self).get(self)
else:
if profile_obj.role_id == 3:
redirect = super(AuthorLoginView, self).form_valid(form)
remember_me = form.cleaned_data.get('remember_me')
if remember_me is True:
ONE_MONTH = 30 * 24 * 60 * 60
expiry = getattr(settings, "KEEP_LOGGED_DURATION", ONE_MONTH)
self.request.session.set_expiry(expiry)
return redirect
答案 0 :(得分:3)
如果None
profile_obj.role_id != 3
if profile_obj.role_id == 3:
redirect = super(AuthorLoginView, self).form_valid(form)
remember_me = form.cleaned_data.get('remember_me')
if remember_me is True:
ONE_MONTH = 30 * 24 * 60 * 60
expiry = getattr(settings, "KEEP_LOGGED_DURATION", ONE_MONTH)
self.request.session.set_expiry(expiry)
return redirect
# HERE need add logic simple return super
return super(AuthorLoginView, self).form_valid(form)