gpt4 book ai didi

Django属性错误: 'NoneType' object has no attribute 'has_header'

转载 作者:行者123 更新时间:2023-12-01 20:24:24 27 4
gpt4 key购买 nike

当我尝试登录仪表板时,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

最佳答案

您返回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)

关于Django属性错误: 'NoneType' object has no attribute 'has_header' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46012120/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com