django-betterFlatPages
This django app is a drop in replacement for django.contrib.flatpages. The main new features that django-betterFlatPages offers as of now is the optional django-rest-framework views and a spot to add metadata. Any contribution is welcome just make a pull request, and I will try to add your feature in the next version as soon as possible.
Installation
-
prerequisites
- sites framework (django.contrib.sites) - make sure you have the site id set
- django-rest-framework (not required unless you want to use betterFlatPages rest api)
-
run
pip install django-betterFlatPages -
Add 'betterFlatPages' to your INSTALLED_APPS setting.
-
Add urls (only add the urls file that you plan on using)
rest api urls
urlpatterns = [ path('api/pages/', include('betterFlatPages.DRF_urls')), ]
normal urls file
urlpatterns = [ path('pages/', include('betterFlatPages.urls')), ]
-
Run the command
manage.py migrate.
using the rest api
to use the rest api django-rest-framework must be installed
to get the page in the rest api add the url at the end of api/pages/
if the flatPage url is /policy/ then it would be `/api/pages/policy/'
the response would look something like
{
"url": "/policy/",
"title": "privacy policy",
"content": "this is the privacy policy",
"enable_comments": false,
"meta": "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"
}
using custom templates
By default, flatpages are rendered via the template betterFlatPages/default.html, but you can override that for a particular flatpage: in the admin, a collapsed fieldset titled “Advanced options” (clicking will expand it) contains a field for specifying a template name. If you’re creating a flat page via the Python API you can set the template name as the field template_name on the FlatPage object. (as per the django documentation)
Flatpage templates are passed a single context variable, flatpage, which is the flatpage object.
here is the current default.html
{% extends 'betterFlatPages/base.html' %}
{% block head_title %}{{ flatpage.title }}{% endblock %}
{% block extra_head %}{{ flatpage.meta | safe}}{% endblock %}
{% block content %}
<div class="bg-white p-5 rounded">
<h1 class="text-center">{{ flatpage.title }}</h1>
{{ flatpage.content | safe }}
</div>
{% endblock %}
using metatags
you can add meta-tags in the admin in “Advanced options" dropdown
add the meta options with the full tag just like it would be in html
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="product" content="cool product">
<meta name="etc" content="etc...">
to render the tags on your template page add
<head>
...
{{ flatpage.meta | safe}}
...
</head>
extending and overriding the template
visit: https://docs.djangoproject.com/en/4.0/howto/overriding-templates/
still left to do
- create a management command to copy all the django.contrib.flatpages pages to better flat pages (and possibly the reverse)
- amazing documentation
- 100% testing coverage
- create a replacement middleware similar to django.contrib.flatpages.middleware.FlatpageFallbackMiddleware
- add any new features django.contrib.flatpages is lacking
- add all the features that django.contrib.flatpages has
- template tags
- integration with django sitemaps
- use marksafe before rendering template so user doesn't have to use the | safe filter
Metadata
Release files for django-betterFlatPages 1.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-betterFlatPages-1.2.2.tar.gz | 23.2 kB | Without provenance | Details for django-betterFlatPages-1.2.2.tar.gz |
Release files / django-betterFlatPages-1.2.2.tar.gz
| Download URL | django-betterFlatPages-1.2.2.tar.gz |
|---|---|
| Size | 23.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cfa710e99e9548e078ff2762b1c7d95c02b5850ee4042864accb8acb568b594c
|
|
BLAKE2b-256 checksum How to use checksums |
25bbaa4837883388b6133cb771151b367a04bc99a380edf2974635b70e15214e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.9.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
|
Security for django-betterFlatPages 1.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.