SmarterNeverCachedWebView
- class smarter.lib.django.views.SmarterNeverCachedWebView(**kwargs)[source]
Bases:
SmarterWebHtmlViewAn optimized web view that requires authentication and is never cached.
This class combines two critical behaviors for secure and dynamic web applications:
Authentication Enforcement: Inherits from SmarterAuthenticatedWebView, which applies the @login_required decorator to the dispatch method. This ensures that only authenticated users can access the view. If an unauthenticated user attempts access, they are redirected to the login page, and the cache is expired to prevent sensitive data leakage.
Cache Prevention: Uses the @never_cache decorator (applied via method_decorator to the dispatch method). This instructs Django and downstream proxies/browsers to never cache responses from this view. This is essential for views that display user-specific or sensitive information, ensuring that no part of the response is stored or reused.
By combining these decorators, SmarterAuthenticatedNeverCachedWebView guarantees that: - Only logged-in users can access the view. - Every response is generated fresh for each request, with no caching at any layer.
This makes it ideal for pages displaying private, frequently changing, or security-sensitive data.
- __init__(**kwargs)
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- classmethod as_view(**initkwargs)
Main entry point for a request-response process.
- clean_http_response(request, template_path, *args, context=None, **kwargs)
Render a template and return an HttpResponse with comments removed.
- Parameters:
request (
HttpRequest) – The HTTP request object.template_path (str) – The path to the template to render.
context (dict, optional) – The context to use for rendering the template.
- Returns:
An HttpResponse with the cleaned HTML content.
- Return type:
HttpResponse
- dispatch(request, *args, **kwargs)
- property formatted_class_name: str
Returns the class name in a formatted string along with the name of this view.
- get(request, *args, **kwargs)
Handle GET requests and return a cleaned HttpResponse.
- Parameters:
request (HttpRequest) – The HTTP request object.
- Returns:
An HttpResponse with the cleaned HTML content.
- Return type:
HttpResponse
- http_method_names = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace']
- http_method_not_allowed(request, *args, **kwargs)
- minify_html(html)
Minify an html string.
- options(request, *args, **kwargs)
Handle responding to requests for the OPTIONS HTTP verb.
- property ready: bool
Returns True if the view is ready to handle requests, False otherwise.
This can be used to check if the necessary context or data is available before processing a request.
- remove_comments(html)
Remove HTML comments from an html string.
- render_clean_html(request, template_path, context=None)
Render a template as a string, with comments removed and minified.
- Parameters:
request (
HttpRequest) – The HTTP request object.template_path (str) – The path to the template to render.
context (dict, optional) – The context to use for rendering the template.
- Returns:
The rendered, cleaned HTML string.
- Return type:
- setup(request, *args, **kwargs)
Initialize attributes shared by all view methods.
- view_is_async = False