SmarterNeverCachedWebView
- class smarter.lib.django.views.SmarterNeverCachedWebView(**kwargs)[source]
Bases:
SmarterWebHtmlViewA web view that is never cached, and does not require authentication.
It extends
SmarterWebHtmlView, notSmarterAuthenticatedWebView, so anonymous users can access it: it neither requires login nor initializesSmarterRequestMixin. For a page that must be both private and never cached, useSmarterAuthenticatedNeverCachedWebView.The
@never_cachedecorator, applied viamethod_decoratorto thedispatchmethod, instructs Django and downstream proxies and browsers to never cache responses from this view, so every response is generated fresh for each request.- __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:
- Return type:
- Returns:
An HttpResponse with the cleaned HTML content, or the error response of
render_clean_html()if the template could not be rendered.
- dispatch(request, *args, **kwargs)
- property formatted_class_name: str
Return the class name in a formatted string along with the name of this view.
- Returns:
The dotted name of this view class and its instance id, formatted for logs.
- get(request, *args, **kwargs)
Handle GET requests and return a cleaned HttpResponse.
A view without a template, e.g. a JSON api that only answers POST, has nothing to render, so a GET receives 405 Method Not Allowed instead of a 500 (issue #963).
- Parameters:
request (
HttpRequest) – The HTTP request object.args – Passed to
clean_http_response().kwargs – Passed to
clean_http_response().
- Return type:
- Returns:
An HttpResponse with the cleaned HTML content, or a 405 response when the view has no template.
- get_not_allowed(request, *args, **kwargs)
Answer a GET to a view that has no template with 405 Method Not Allowed.
Django’s own
http_method_not_allowed()never runs for these views, because this class definesget(). ItsAllowheader would list GET and HEAD, so they are removed.- Parameters:
request (
HttpRequest) – The HTTP request object.args – Passed to
http_method_not_allowed().kwargs – Passed to
http_method_not_allowed().
- Return type:
- Returns:
A 405 response whose
Allowheader lists the methods that the view handles.
- 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, by removing the whitespace between tags.
It is one regular expression, not a parse:
HTMLMinifyMiddlewareparses every html response anyway.
- options(request, *args, **kwargs)
Handle responding to requests for the OPTIONS HTTP verb.
- property ready: bool
Return 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.
- Returns:
True if the view is ready.
- 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:
- Return type:
- Returns:
The rendered, cleaned HTML string, or a 500 response if the template could not be rendered.
- setup(request, *args, **kwargs)
Initialize attributes shared by all view methods.
- view_is_async = False