Y
Y
Yury2016-10-26 13:18:59
Django
Yury, 2016-10-26 13:18:59

How to write an analogue of “ListView.as_view” in Django in urls.py without a template?

How to write an analogue of "ListView.as_view" in Django in urls.py without a template?
"url(r'Author/(?P\d+)/', DetailView.as_view(model=Author))" works for detail entry,
but how to write similarly for displaying a list?
I try like this:
url(r'Authors', ListView.as_view(model=Author, paginate_by=25))
says - template is needed.
I would like to ideally get an auto form for displaying a list in one line and only according to the model, without forms, views, templates and other things

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri, 2016-10-26
@Ba1t

In order for Django to find the default template for a ListView, it must be named modelname_list.html . For example, if the model is named ' Post ', then the template should be named ' post_list.html '.
Don't forget the Zen of Python:

"Explicit is better than implicit."

The fact that you are trying to write a little less code in this way will affect the future. Climb (or worse, someone else instead of you) look for a view in views.py, but it's not there ... Separate the flies from the cutlets.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question