pythondjangodjango-flatpages

How to get a flatpage as a variable in views.py and pass it to another view?


I have some flatpages and I need to display it's content in a separate view.

What I am doing right now is to get those flatpages by url in the actual view using something like:

{% load flatpages %}
{% get_flatpages '/about/' as about_pages %}

Following the documentation I found in https://docs.djangoproject.com/en/1.9/ref/contrib/flatpages/

I would like to get those flatpages in my views.py and pass them as variables to whatever view I want.

Any idea about how to accomplish this?


Solution

  • Flatpages are just models, like anything else; you can query them and pass the instances around however you like.

    from django.contrib.flatpages.models import FlatPage
    flatpage = FlatPage.objects.get(url='/about/)