Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#31484 closed New feature (wontfix)

Possibility to provide additional Context to Render a FlatPage.

Reported by: thaxy Owned by: nobody
Component: contrib.flatpages Version: dev
Severity: Normal Keywords: flatpage context template render
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello,

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>

Change History (2)

comment:1 by Mariusz Felisiak, 5 years ago

Easy pickings: unset
Resolution: wontfix
Status: newclosed
Summary: Possibility to provide additional Context to Render a FlatPagePossibility to provide additional Context to Render a FlatPage.
Version: master

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 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, ..."

comment:2 by Adam Johnson, 5 years ago

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?

Note: See TracTickets for help on using tickets.
Back to Top