In one of my projects, I am using the Django flatpages app/feature. This
worked fine so far but I have stumbled across a use case where I want to
{% include %} another template within the template of my flatpage. The
included template requires additional context data to work correctly.
The current implementation of the render function of the flatpage doesn't
allow the developer to add additional context data other than the flatpage
itself. (see:
https://github.com/django/django/blob/master/django/contrib/flatpages/views.py#L69).
One solution could be to allow additional `**kwargs` to be passed to the
render_flatpage function eventually being used to call the template.render
function.
Is this worth thinking about? In my opinion, this could be an improvement
- that's why I am writing to you. I could also try to create a PR
according to the guidelines if you think this is an improvement.
Some code to illustrate the problem:
**urls.py:**
{{{
path('texte/', views.flatpage, {'url': '/texte/'}, name='texte')
}}}
**texte.html:**
{{{
{% extends 'base.html' %}
{% block content %}
<div class="content">
{{ flatpage.content }}
</div>
{% include 'texte/uebersicht.html' %}
{% endblock content %}
}}}
**texte/uebersicht.html:**
{{{
<ul>
{% for p in prosa %} <!-- prosa is a queryset -->
<li>
<a href="{% url 'prosa' p.slug %}">{{ p }}</a>
</li>
{% empty %}
keine inhalte gefunden
{% endfor %}
</ul>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31484>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* version: => master
* resolution: => wontfix
* easy: 1 => 0
Comment:
Thanks for this ticket, however I don't think it's the right usage of
flatpages, because page that render a queryset is not "flat" anymore (see
[https://docs.djangoproject.com/en/3.0/ref/contrib/flatpages/#module-
django.contrib.flatpages documentation]:
> ''"It lets you store “flat” HTML content in a database ...
> A flatpage is a object with a URL, title and content. Use it for one-
off, special-case pages, such as “About” or “Privacy Policy” pages, ..."''
--
Ticket URL: <https://code.djangoproject.com/ticket/31484#comment:1>
Comment (by Adam (Chainz) Johnson):
You can add custom context with a context processor:
https://docs.djangoproject.com/en/3.0/ref/templates/api/#writing-your-own-
context-processors .
Maybe that is more suitable for your use case?
--
Ticket URL: <https://code.djangoproject.com/ticket/31484#comment:2>