Skip to main content

Django Frontpage

Show a page before your users authenticate into the admin site.

Build Status Coverage Status PyPI version

Valid users will go straight to the admin site, others will land in the frontpage where you can show an app description, warning, etc. You only need to provide your own template.

After clicking the login button in the frontpage, the user will be redirected to the original url. If there was no original url, the user will be redirected to the FRONTPAGE_ADMIN_PREFIX.

Getting started

Works with Django version 2.0 to 3.1.

Tested with Django-supported Python versions.

Install:

pip install django-frontpage

Then modify your Django settings:

Add the frontpage application to INSTALLED_APPS:

INSTALLED_APPS = (
  ...
  'frontpage',
  ...
)

Add the middleware to MIDDLEWARE after AuthenticationMiddleware or any other authentication middleware like OAuth2:

MIDDLEWARE = [
    ...
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'oauth2_provider.backends.OAuth2Backend',
    'frontpage.middleware.FrontpageMiddleware',
    ...
]

Default admin prefix is '/admin/' change it if necessary:

FRONTPAGE_ADMIN_PREFIX = '/admin/'

Add the frontpage view to your urls:

from frontpage.views import FrontpageView

urlpatterns = [
    path('', FrontpageView.as_view(), name='frontpage'),
    path('admin/', admin.site.urls),
    ...
]

Demo

Here's how the default template looks like:

Screenshot of default template

Custom frontpage template

Place a different frontpage template in frontpage/index.html.

Or use the template_name attribute in urls.py:

from frontpage.views import FrontpageView

urlpatterns = [
    path('', FrontpageView.as_view(template_name='my_frontpage.html'), name='frontpage'),
    path('admin/', admin.site.urls),
    ...
]

See frontpage/templates/frontpage/index.html for the default frontpage template.

Settings

Option Default Description
FRONTPAGE_ADMIN_PREFIX '/admin/' mandatory, the path of the admin site.
FRONTPAGE_URL_NAME 'frontpage' name of the frontpage url
FRONTPAGE_LOGIN_URL_NAME 'admin:login' name of the login url
FRONTPAGE_LOGOUT_URL_NAME 'admin:logout' name of the logout url
FRONTPAGE_RELOGIN_URL_NAME 'admin:login' name of the relogin url

Frontpage needs to know about the logout url because that one should not be redirected.

Relogin is necessary if you are logged in as an user that does not have access to the admin. You may need to implement a custom view to logout the user then redirect to some login URL.

Flow

When the frontpage is accessed then:

  • if the user is_authenticated and is_staff then:
    • the user will be redirected to the admin site
  • if the user is_authenticated but NOT is_staff then:
    • frontpage is rendered with a specific message
  • if the user is anonymous then:
    • frontpage is rendered with a specific message

When any page of the admin site is accessed then:

  • if the user is_authenticated and is_staff then:
    • everything is ok, frontpage will do nothing here
  • if the user is_authenticated but NOT is_staff then:
    • the user will be redirected to the frontpage page
  • if the user is anonymous then:
    • the user will be redirected to the frontpage page

Tests

pip install -r requirements-dev.txt
pip install Django
pytest

Authors

Metadata

Release files for django-frontpage 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-frontpage 1.0.3
File Size Uploaded Provenance Actions
django-frontpage-1.0.3.tar.gz 5.8 kB Without provenance Details for django-frontpage-1.0.3.tar.gz

Release files / django-frontpage-1.0.3.tar.gz

Download URL django-frontpage-1.0.3.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
de566f9ba21e495ea44d8750da01f69bcbb7cdc5bd99e0df2d523f2ffbbd490c
BLAKE2b-256 checksum
How to use checksums
8a316d420edda5e942f986027c9238c33cf51bb8e1914e1321b2088bbb429d1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.7

Security for django-frontpage 1.0.3

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.

Release history Release notifications | RSS feed

This release

1.0.3 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page