A Wagtail package which will give you ability to automatically log and create of redirects from within Wagtail admin panel.
- Automatic "404 Not Found" HTTP Error Detection Following the Non-Existent Page Opening
- Support for Redirects to Wagtail Pages
Regular Expression → Regular Expression
[currently in development]Regular Expression → URL
Regular Expression → Wagtail Page
URL → URL
URL → Wagtail Page
- wagtail_managed404 - abandoned in 2018
- django-regex-redirects.
Both projects were similar (one Model
class and fairly uncomplicated Middleware
), so the easiest thing was simply to combine them, and work onwards from this base.
Below, you can see the classes comparison of those two.
Django Regex Redirects | Wagtail Managed 404 (Cjk404) |
---|---|
class Redirect(models.Model) |
class PageNotFoundEntry(models.Model) |
• old_path |
• url |
• new_path |
• redirect_to_url or redirect_to_page |
• regular_expression |
- |
• fallback_redirect |
- |
• nr_times_visited |
• hits |
Use either Django test runner (python manage.py test cjk404
) or pytest.
- wagtail.contrib.modeladmin (https://docs.wagtail.io/en/stable/reference/contrib/modeladmin/index.html)
This package is used for the admin panel itself.
-
Get the app from PyPI:
pip install wagtail-cjk404
-
Add 'cjk404' to the INSTALLED_APPS:
INSTALLED_APPS = [
...
'wagtail_modeladmin', # required dependency
'cjk404'
...
]
- Add the supplied middleware. You may also want to disable Wagtail's default
RedirectMiddleware
:
MIDDLEWARE = [
'cjk404.middleware.PageNotFoundRedirectMiddleware',
# "wagtail.contrib.redirects.middleware.RedirectMiddleware",
]
- Run the migrations:
python manage.py migrate
- Visit the Wagtail admin area. You should see any 404s recorded in the application, and you can add redirects to them. You can also add your own redirects, e.g. based on regexp.
- Remove folder
apps/cjk404
with all contents - Change 'apps.cjk404' to 'cjk404' in INSTALLED_APPS.
- Get the app from PyPI: ```pip install wagtail-cjk404``
- You're done!
Assuming you have Django>=4.0 and Wagtail>=3.0 pip-installed in your virtual environment, you do not need to set up a new Django/Wagtail project to develop/test the app.
After you git clone
the repository, use load_tests.py
to call boot_django
and then to execute the unit tests.
https://github.com/cjkpl/dj-apps-cjk404
https://github.com/cjkpl/wagtail-cjk404
Please migrate your local repositories to the new URL by executing:
$ git remote set-url origin https://github.com/cjkpl/wagtail-cjk404