0
장고 1.11.3을 사용하고 관리자의 일부 모델에서 "저장"버튼을 누른 후 사용자를 리디렉션하려고합니다. 그래서, 내 admin.py
파일에 나는 코드 (의 일부) 다음과 같습니다'NoneType'개체에 'has_header'속성이 없습니다.
from django.contrib import admin
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.http import HttpResponseRedirect
from .models import Info
class InfoAdmin(admin.ModelAdmin):
def response_change(self, request, object, form_url=''):
if(object.type == 1):
return HttpResponseRedirect('/admin/pict/data/add/?info=' + str(object.info))
else:
return HttpResponseRedirect('/admin/pict/article/')
admin.site.register(Info, InfoAdmin)
을하지만 버튼을 누른 후 나는 다음과 같은 오류가 발생합니다 : 내가 redirect
과 HttpResponse
으로도 시도
AttributeError at /admin/pict/info/58/change/
'NoneType' object has no attribute 'has_header'
을 , 오류는 계속 발생합니다.
전체 역 추적 : 내가 잘못 뭐하는 거지
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/pict/info/58/change/
Django Version: 1.11.3
Python Version: 3.5.2
Installed Applications:
['pict.apps.PictConfig',
'suit',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'massadmin']
Installed Middleware:
['whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/Users/mick/.virtualenvs/gbs/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
41. response = get_response(request)
File "/Users/mick/.virtualenvs/gbs/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/Users/mick/.virtualenvs/gbs/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/mick/.virtualenvs/gbs/lib/python3.5/site-packages/django/contrib/admin/options.py" in wrapper
551. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Users/mick/.virtualenvs/gbs/lib/python3.5/site-packages/django/utils/decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "/Users/mick/.virtualenvs/gbs/lib/python3.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
58. add_never_cache_headers(response)
File "/Users/mick/.virtualenvs/gbs/lib/python3.5/site-packages/django/utils/cache.py" in add_never_cache_headers
274. patch_response_headers(response, cache_timeout=-1)
File "/Users/mick/.virtualenvs/gbs/lib/python3.5/site-packages/django/utils/cache.py" in patch_response_headers
265. if not response.has_header('Expires'):
Exception Type: AttributeError at /admin/pict/info/58/change/
Exception Value: 'NoneType' object has no attribute 'has_header'
?
감사합니다. 매번 obj.type이 ** 1 ** 일 때도 (인쇄물을 기반으로)'/ admin/pict/article /'로 리디렉션됩니다. 어떤 생각? – user8980530
'repr (obj.type)'과'type (obj.type)'이 무엇인지 확인하십시오. 아마도'obj.type'은 정수'1'이 아닌''1'' 문자열입니다. – Alasdair
예, 유형이 문제였습니다. 많은 감사합니다! – user8980530