Django - 基于类的通用视图 - “没有要重定向到的 URL”
我正在使用通用的 CreateView,例如:
#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 模板,例如:
<form method="post" action="">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
当我提交表单时,会创建新对象,但出现错误
配置不正确...
没有网址 重定向到.要么提供一个网址,要么 定义一个 get_absolute_url 方法 模型。
如何指定成功时重定向的 url?
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/
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 ...
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 ?
, CreateView.as_view(model=myModel)),
)
With a mymodel_form.html template like:
When I submit my form, the new object is created but I get the error
ImproperlyConfigured at ...
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您是否尝试过传入
success_url
?例如,或者如果您想重定向到命名视图:
Have you tried passing in
success_url
? e.g.or if you want to redirect to a named view:
您还可以尝试在模型中定义 get_absolute_url 。例如
you can also try to define get_absolute_url in your models. For example
添加视图:
Add in views:
views.py/
urls.py/ (您的应用程序的)
views.py/
urls.py/ (of your app)