/edit-narration/13/edit/ 处的模板不存在

TemplateDoesNotExist at /edit-narration/13/edit/

为什么我的 narrate_update_form 模板没有显示?为什么我得到

TemplateDoesNotExist at /narration/7/edit/

narrate_update_form

我的 views.py 是:

class NarrateUpdate(UpdateView):
    model = Narrate
    fields = ['title', 'body']
    template_name = 'narrate_update_form'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['narrate'] = Narrate.objects.get(pk=self.kwargs['pk'])
        return context

在我的叙述模板上有这个按钮:

<a href="{% url 'edit-narration' narrate.pk %}" value="Update">Edit/Update</a>

在 narrate_update_form.html 上,我有:

{% extends 'base.html' %}
{% block body %}
<form method="post">{% csrf_token %}
    {{ form.as_p }}
   <input type="submit" value="Update">
</form>
{% endblock body %}

谁能帮帮我?

应该是 template_name = 'narrate_update_form.html',您需要在此处添加 html

另外,根据模板文件的实际位置,您可能需要指定它的相对路径。