Skip to content
Discussion options

You must be logged in to vote

I believe you can’t replace existing forms or the templates used by their related views because they’re hard-coded. However, you can use a middleware to intercept specific requests and redirect them to a custom view instead. This custom view can then add additional logic.

from collections.abc import Callable

from django.http import HttpRequest, HttpResponse
from django.shortcuts import redirect
from django.urls import resolve


class RedirectMiddleware:
    def __init__(self, get_response: Callable) -> None:
        self.get_response = get_response

    def __call__(self, request: HttpRequest) -> HttpResponse:
        resolver_match = resolve(request.path_info)

        if resolver_match.v…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@marto1
Comment options

Answer selected by marto1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants