django UpdateView 如何找到 html 表单? (名称约定)

How does django UpdateView find a html form? (name convention)

我正在学习 django 教程并且一切正常,但我不明白这个 class 在 views.py 中如何找到 album_form.html 如果我没有通过path/name.

的任何参数
class AlbumCreate(CreateView):
    model = Album
    fields = ['artist' , 'album_title' , 'genre' , 'album_logo']

html 名称是 album_form.html 并且工作正常,但是如果我更改为 somethingelse_form.html 它就不再工作了。 django 从哪里确定它必须使用 'album' 而不是 'somethingelse'?命名规则是什么?

它不是来自 urls.py,因为我的是这样的:

url(r'album/add/$', views.AlbumCreate.as_view(), name='album-add')

这是CreateView class.

class CreateView(SingleObjectTemplateResponseMixin, BaseCreateView):
    template_name_suffix = '_form'

如您所见,它具有 class 属性 template_name_suffix,用于 SingleObjectTemplateResponseMixinget_template_names 被调用时。

这是用于构造 template_name 值的模式。

`<app_label>/<model_name><template_name_suffix>.html`

这就是它呈现 album_form.html 而未在您的视图中指定 template_name 的原因。

django docs里面也有解释。