我希望success_url
在表单提交并有效后将其重定向到相同的表单.在线我找到了解决方案的描述,但是这个解决方案和我的其他代码选项会生成相同的错误消息.
Exception Value: 'NoneType' object has no attribute 'find'urls.py
url(r'^pictures/(?P1st views.py选项\d+)/$', PictureUpload.as_view(), name='picture_upload'), ...
复制现有的链接路径
class PictureUpload(FormView): form_class = PictureForm template_name = 'picture_upload.html' def get_success_url(self): success_url = lambda self: self.request.path第二个views.py选项
根据反向URL和id重新创建链接路径
class PictureUpload(FormView): form_class = PictureForm template_name = 'picture_upload.html' def get_success_url(self): success_url = reverse('picture_upload', kwargs={'id': self.kwargs.get('id', None)})两个选项最终都在同一回溯中.
Request Method: POST Request URL: http://127.0.0.1:8000/pictures/2/ Django Version: 1.5.1 Python Version: 2.7.1 Installed Applications: ('django.contrib.admin', 'django.contrib.admindocs', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.gis', 'django.contrib.humanize', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', 'django.contrib.admindocs', 'picture', 'debug_toolbar') Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'debug_toolbar.middleware.DebugToolbarMiddleware') Traceback: File "/Users/Development/virtual-re/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 115. response = callback(request, *callback_args, **callback_kwargs) File "/Users/Development/virtual-re/lib/python2.7/site-packages/django/views/generic/base.py" in view 68. return self.dispatch(request, *args, **kwargs) File "/Users/Development/virtual-re/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch 86. return handler(request, *args, **kwargs) File "/Users/Development/virtual-re/lib/python2.7/site-packages/django/views/generic/edit.py" in post 165. return self.form_valid(form) File "/Users/Development/project/apps/picture/picture_views.py" in form_valid 180. return super(PictureUpload, self).form_valid(form) File "/Users/Development/virtual-re/lib/python2.7/site-packages/django/views/generic/edit.py" in form_valid 65. return HttpResponseRedirect(self.get_success_url()) File "/Users/Development/virtual-re/lib/python2.7/site-packages/django/http/response.py" in __init__ 388. parsed = urlparse(redirect_to) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urlparse.py" in urlparse 134. tuple = urlsplit(url, scheme, allow_fragments) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urlparse.py" in urlsplit 173. i = url.find(':') Exception Type: AttributeError at /pictures/2/ Exception Value: 'NoneType' object has no attribute 'find'
Peter DeGlop.. 10
看起来你的get_success_url
实现都没有实际返回URL,所以假设这不只是一个剪切和粘贴错误,你将None传递给HttpResponseRedirect.
看起来你的get_success_url
实现都没有实际返回URL,所以假设这不只是一个剪切和粘贴错误,你将None传递给HttpResponseRedirect.