Search code examples
djangodjango-flatpages

What is the content field for in Django admin for Flatpages?


I've installed Flatpages and have a few pages set up to load off of specific templates. Though the templates I'm using now are doing just fine, I'd love to be able to easily make parts of it editable by other non-technical admins. So I've been wondering—every time I go into Django admin for Flatpages, I see this big text area for content:

Django admin for Flatpages

Is there some way I can use that to make parts of my template editable by others? As you can see, I tried saving some text in there to see what happened, and it didn't show up on the page. I also tried creating a Flatpage without pointing to a specific template (besides default.html) and put HTML into the content field, but again the content didn't show up. What is the purpose of the content field?


Solution

  • Just output this field in the template. For example:

    {% extends 'base.html' %}
    
    {% block title %}{{ flatpage.title }}{% endblock %}
    
    {% block content %}    
        <h1>{{ flatpage.title }}</h1>    
        {{ flatpage.content|safe }}    
    {% endblock %}