Instead of following function based view logic in link, we can use predefined logic from class based views.
views.py
from django.views.generic import ListView,DetailView class NotesListView(ListView): model = Notes context_object_name = "notes" template_name = "notes/notes_list.html" ##optional to pass template as uses default template class NotesDetailView(DetailView): model = Notes context_object_name = "note"
urlpatterns = [ path('notes',views.NotesListView.as_view()), path('notes/<int:pk>',NotesDetailView.as_view()), ]
No comments:
Post a Comment