Shortcuts (feincms3.shortcuts
)¶
For me, the most useful part of Django’s generic class based views is the template name generation and the context variable naming for list and detail views, and also the pagination.
The rest of the CBV is less flexible than I’d like them to be, i.e. integrating forms on detail pages can be a hassle.
Because of this, render_list
and render_detail
.
- feincms3.shortcuts.render_detail(request, object, context=None, *, template_name_suffix='_detail')[source]¶
Render a single item
Usage example:
def article_detail(request, slug): article = get_object_or_404(Article.objects.published(), slug=slug) return render_detail( request, article, )
An additional context dictionary is also supported, and specifying the template name suffix too.
The
Article
instance in the example above is passed asobject
ANDarticle
(lowercased model name) into the template.
- feincms3.shortcuts.render_list(request, queryset, context=None, *, model=None, paginate_by=None, template_name_suffix='_list')[source]¶
Render a list of items
Usage example:
def article_list(request, ...): queryset = Article.objects.published() return render_list( request, queryset, paginate_by=10, )
You can also pass an additional context dictionary and/or specify the template name suffix. The query parameter
page
is hardcoded for specifying the current page if using pagination.The queryset (or the page if using pagination) are passed into the template as
object_list
AND<model_name>_list
, i.e.article_list
in the example above.