在Django中,CreateView和UpdateView是否具有默认模板名称?

2024-04-24 23:11:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在关注YouTube教程,据我所知,视频创建者在URL模式中添加PostUpdateView和PostCreateView时没有指定模板名称。这两个视图是否都有默认的模板名为“您的模型名”\u form.html?因为我有一个post_form.html模板,我看不到任何明显引用它的URL模式


Tags: 模型form名称视图模板url视频youtube
1条回答
网友
1楼 · 发布于 2024-04-24 23:11:08

是的,它有,as documented here

template_name_suffix

The UpdateView page displayed to a GET request uses a template_name_suffix of _form. For example, changing this attribute to _update_form for a view updating objects for the example Author model would cause the default template_name to be myapp/author_update_form.html.

A similar pattern申请CreateView

因此,create和update视图的默认模板都是myapp/<model_name>_form.html

相关问题 更多 >