[英]“Unsafe redirect to URL with protocol 'content-type'” error in Django view
I'm having this problem with this use of the get_success_url()
in my CreateView
class: 我在CreateView
类中使用get_success_url()
遇到了这个问题:
def get_success_url(self):
search = searchViews.getIndexInstance()
search.mainfunc(self.contentForSearch, self.discussion.pk)
return HttpResponseRedirect(reverse('discussion-detail', kwargs={'slug':self.discussion.slug}))
Here's the complete error stacktrace: 这是完整的错误堆栈跟踪:
Traceback:
File "/home/nithin/djangopro/djangoenv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/nithin/djangopro/djangoenv/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
71. return self.dispatch(request, *args, **kwargs)
File "/home/nithin/djangopro/djangoenv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
34. return bound_func(*args, **kwargs)
File "/home/nithin/djangopro/djangoenv/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
22. return view_func(request, *args, **kwargs)
File "/home/nithin/djangopro/djangoenv/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
30. return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/nithin/djangopro/viewanalyse/discussion/views.py" in dispatch
30. return super(LoggedInMixin, self).dispatch(*args, **kwargs)
File "/home/nithin/djangopro/djangoenv/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
89. return handler(request, *args, **kwargs)
File "/home/nithin/djangopro/djangoenv/local/lib/python2.7/site-packages/django/views/generic/edit.py" in post
249. return super(BaseCreateView, self).post(request, *args, **kwargs)
File "/home/nithin/djangopro/djangoenv/local/lib/python2.7/site-packages/django/views/generic/edit.py" in post
215. return self.form_valid(form)
File "/home/nithin/djangopro/viewanalyse/discussion/views.py" in form_valid
374. return super(DiscussionContentUpdateCreateView, self).form_valid(form)
File "/home/nithin/djangopro/djangoenv/local/lib/python2.7/site-packages/django/views/generic/edit.py" in form_valid
194. return super(ModelFormMixin, self).form_valid(form)
File "/home/nithin/djangopro/djangoenv/local/lib/python2.7/site-packages/django/views/generic/edit.py" in form_valid
108. return HttpResponseRedirect(self.get_success_url())
File "/home/nithin/djangopro/djangoenv/local/lib/python2.7/site-packages/django/http/response.py" in __init__
456. raise DisallowedRedirect("Unsafe redirect to URL with protocol '%s'" % parsed.scheme)
Exception Type: DisallowedRedirect at /discussion/discussion-content-update/why-i-believe-in-reincarnation-g-hijo-2015-08-09-162236316999/
Exception Value: Unsafe redirect to URL with protocol 'content-type'
What's the cause and how can I fix this? 原因是什么?如何解决这个问题?
The get_success_url
method should return a URL , not an HTTP response. get_success_url
方法应返回URL ,而不是HTTP响应。
def get_success_url(self):
search = searchViews.getIndexInstance()
search.mainfunc(self.contentForSearch, self.discussion.pk)
return reverse('discussion-detail',kwargs={'slug':self.discussion.slug})
It's not clear what the first two lines are for, they don't seem to be used by the reverse()
call. 目前尚不清楚前两行是什么,它们似乎没有被reverse()
调用使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.