在Django 2.0中,基于类的视图显示预期的列表,但基于函数的视图不显示

时间:2019-05-06 02:36:21

标签: django templates

我正在运行Django 2.0项目和组件。我编写了基于类的视图和基于函数的视图进行比较。网址http://localhost:8000/list/显示预期的输出。但是,当我在浏览器中输入http://localhost:8000/list-fbv/时,它返回错误:/ list-fbv /中的 TemplateDoesNotExist notes / notes_list.hmtl 。我做错了什么?

views.py

class NotesListView(ListView):
    context_object_name = 'notes_list'
    queryset = Notes.objects.all()

def notes_list_view(request):
    queryset = Notes.objects.all()
    context = {
        'notes_list': queryset
    }
    return render(request, "notes/notes_list.hmtl", context)

urls.py:

urlpatterns = [
    path('list/', NotesListView.as_view(), name='notes_list'),
    path('list-fbv/', notes_list_view),
    path('detail/<int:id>/', NotesDetailView.as_view(), name='notes_detail'),
    path('detail-fbv/<int:pk>/', notes_detail_view),
]

notes_list.html

{% extends 'notes/_base.html' %}
{% block content %}
    {% for note in notes_list %}

        <p>{{note.title}}</p>
        <p>{{note.text}}</p>
        <p>{{note.timestamp}}</p>

    {% endfor %}
{% endblock content %}

0 个答案:

没有答案
相关问题