- class dynamic_forms.middlewares.FormModelMiddleware¶
This middleware intercepts all HTTP 404 responses and checks if there is a form mapped to this URL. This way an explicit URL mapping from the projects ROOT_URLCONF cannot accidentally be overridden by wrong setting for submit_url or success_url on dynamic_forms.models.FormModel.
This technique is comparable to the one used by Django’s FlatpageFallbackMiddleware.
- process_response(request, response)¶
The algorithm that decides if and which form to display works like this:
If the status_code for response is not 404 (NOT FOUND) this the FormModelMiddleware will return the response as-is and will not modify it. Thus, server error (5xx) will also not be affected by the middleware.
Since the success_url of a FormModel is not necessarily be unique, the first model that matches the request path will be used.
If any errors occur while processing a form the original request is returned (if DEBUG = True the respective exception is raised).