Django ships with a Flatpages application that enables the user to create flat HTML pages and store it in the database.
It can be very handy for pages like About, Privacy Policy, Cookies Policy and so on.
Basically it works like this: You define a master page for the content to be displayed, the user creates a new flatpage
in the Django Admin interface, picks a URL and add the content. The user can also select if the page requires login or
not.
Installation
First add the sites and flatpages contrib apps to your INSTALLED_APPS:
If you wasn’t using the sites app, you may also need to add a SITE_ID to the settings.py file:
Now update your urls.py with the flatpages urls:
Migrate the database:
Add a default template for the flatpages. The default location is flatpages/default.html:
The important part here is this two variables: flatpage.title and flatpage.content.
Usage
Go to the Django Admin and add a new page. It should be very intuitive.
Save it and go to the flatpage URL, that is /pages/privacy/:
Rendering a List of Flatpages
You can list all the available flatpages like this in a template:
You can try this Bootstrap template snippet:
It will look something like that:
More
If you want to find out more about the Flatpages app, refer to the
Django’s Official documentation about it.