Django - Class Based Generic View - “No URL to redirect to” [英] Django - Class Based Generic View - "No URL to redirect to"
本文介绍了Django - Class Based Generic View - “No URL to redirect to”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用通用的CreateView,如:
I'm using the generic CreateView like:
#urls.py
from django.conf.urls.defaults import *
from django.views.generic import CreateView
from content.models import myModel
urlpatterns = patterns('myApp.views',
(r'myCreate/$', CreateView.as_view(model=myModel)),
)
使用mymodel_form.html模板,如:
With a mymodel_form.html template like:
<form method="post" action="">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
当我提交表单时,新对象被创建,但是我收到错误
When I submit my form, the new object is created but I get the error
不正确地配置在...
ImproperlyConfigured at ...
没有URL到
重定向到。提供一个url或
在
上定义一个get_absolute_url方法。
No URL to redirect to. Either provide a url or define a get_absolute_url method on the Model.
如何指定网址要成功重定向?
How can I specify the url to redirect on success ?
推荐答案
你尝试传递 success_url
?例如
CreateView.as_view(model=myModel, success_url="/success/")
或者要重定向到命名视图:
or if you want to redirect to a named view:
CreateView.as_view(model=myModel, success_url=reverse('success-url'))
这篇关于Django - Class Based Generic View - “No URL to redirect to”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文