neulab/docprompting-conala huggingface dataset:
sensitive_post_parameters(*parameters)  
If one of your views receives an HttpRequest object with POST parameters susceptible to contain sensitive information, you may prevent the values of those parameters from being included in the error reports using the sensitive_post_parameters decorator: from django.views.decorators.debug import sensitive_post_parameters

@sensitive_post_parameters('pass_word', 'credit_card_number')
def record_user_profile(request):
    UserProfile.create(
        user=request.user,
        password=request.POST['pass_word'],
        credit_card=request.POST['credit_card_number'],
        name=request.POST['name'],
    )
    ...
 In the above example, the values for the pass_word and credit_card_number POST parameters will be hidden and replaced with stars (**********) in the request’s representation inside the error reports, whereas the value of the name parameter will be disclosed. To systematically hide all POST parameters of a request in error reports, do not provide any argument to the sensitive_post_parameters decorator: @sensitive_post_parameters()
def my_view(request):
    ...
 All POST parameters are systematically filtered out of error reports for certain django.contrib.auth.views views (login, password_reset_confirm, password_change, and add_view and user_change_password in the auth admin) to prevent the leaking of sensitive information such as user passwords.
sensitive_variables(*variables)  
If a function (either a view or any regular callback) in your code uses local variables susceptible to contain sensitive information, you may prevent the values of those variables from being included in error reports using the sensitive_variables decorator: from django.views.decorators.debug import sensitive_variables

@sensitive_variables('user', 'pw', 'cc')
def process_info(user):
    pw = user.pass_word
    cc = user.credit_card_number
    name = user.name
    ...
 In the above example, the values for the user, pw and cc variables will be hidden and replaced with stars (**********) in the error reports, whereas the value of the name variable will be disclosed. To systematically hide all local variables of a function from error logs, do not provide any argument to the sensitive_variables decorator: @sensitive_variables()
def my_function():
    ...
  When using multiple decorators If the variable you want to hide is also a function argument (e.g. ‘user’ in the following example), and if the decorated function has multiple decorators, then make sure to place @sensitive_variables at the top of the decorator chain. This way it will also hide the function argument as it gets passed through the other decorators: @sensitive_variables('user', 'pw', 'cc')
@some_decorator
@another_decorator
def process_info(user):
    ...
gzip_page()  
This decorator compresses content if the browser allows gzip compression. It sets the Vary header accordingly, so that caches will base their storage on the Accept-Encoding header.
last_modified(last_modified_func)  
These decorators can be used to generate ETag and Last-Modified headers; see conditional view processing.
require_http_methods(request_method_list)  
Decorator to require that a view only accepts particular request methods. Usage: from django.views.decorators.http import require_http_methods

@require_http_methods(["GET", "POST"])
def my_view(request):
    # I can assume now that only GET or POST requests make it this far
    # ...
    pass
 Note that request methods should be in uppercase.
require_safe()  
Decorator to require that a view only accepts the GET and HEAD methods. These methods are commonly considered “safe” because they should not have the significance of taking an action other than retrieving the requested resource.  Note Web servers should automatically strip the content of responses to HEAD requests while leaving the headers unchanged, so you may handle HEAD requests exactly like GET requests in your views. Since some software, such as link checkers, rely on HEAD requests, you might prefer using require_safe instead of require_GET.
vary_on_headers(*headers)  
The Vary header defines which request headers a cache mechanism should take into account when building its cache key. See using vary headers.
class django.views.generic.base.ContextMixin  
Attributes  
extra_context  
A dictionary to include in the context. This is a convenient way of specifying some context in as_view(). Example usage: from django.views.generic import TemplateView
TemplateView.as_view(extra_context={'title': 'Custom Title'})
 
 Methods  
get_context_data(**kwargs)  
Returns a dictionary representing the template context. The keyword arguments provided will make up the returned context. Example usage: def get_context_data(self, **kwargs):
    context = super().get_context_data(**kwargs)
    context['number'] = random.randrange(1, 100)
    return context
 The template context of all class-based generic views include a view variable that points to the View instance.  Use alters_data where appropriate Note that having the view instance in the template context may expose potentially hazardous methods to template authors. To prevent methods like this from being called in the template, set alters_data=True on those methods. For more information, read the documentation on rendering a template context.
extra_context  
A dictionary to include in the context. This is a convenient way of specifying some context in as_view(). Example usage: from django.views.generic import TemplateView
TemplateView.as_view(extra_context={'title': 'Custom Title'})
get_context_data(**kwargs)  
Returns a dictionary representing the template context. The keyword arguments provided will make up the returned context. Example usage: def get_context_data(self, **kwargs):
    context = super().get_context_data(**kwargs)
    context['number'] = random.randrange(1, 100)
    return context
 The template context of all class-based generic views include a view variable that points to the View instance.  Use alters_data where appropriate Note that having the view instance in the template context may expose potentially hazardous methods to template authors. To prevent methods like this from being called in the template, set alters_data=True on those methods. For more information, read the documentation on rendering a template context.
class django.views.generic.base.RedirectView  
Redirects to a given URL. The given URL may contain dictionary-style string formatting, which will be interpolated against the parameters captured in the URL. Because keyword interpolation is always done (even if no arguments are passed in), any "%" characters in the URL must be written as "%%" so that Python will convert them to a single percent sign on output. If the given URL is None, Django will return an HttpResponseGone (410). Ancestors (MRO) This view inherits methods and attributes from the following view:  django.views.generic.base.View  Method Flowchart  setup() dispatch() http_method_not_allowed() get_redirect_url()  Example views.py: from django.shortcuts import get_object_or_404
from django.views.generic.base import RedirectView

from articles.models import Article

class ArticleCounterRedirectView(RedirectView):

    permanent = False
    query_string = True
    pattern_name = 'article-detail'

    def get_redirect_url(self, *args, **kwargs):
        article = get_object_or_404(Article, pk=kwargs['pk'])
        article.update_counter()
        return super().get_redirect_url(*args, **kwargs)
 Example urls.py: from django.urls import path
from django.views.generic.base import RedirectView

from article.views import ArticleCounterRedirectView, ArticleDetailView

urlpatterns = [
    path('counter/<int:pk>/', ArticleCounterRedirectView.as_view(), name='article-counter'),
    path('details/<int:pk>/', ArticleDetailView.as_view(), name='article-detail'),
    path('go-to-django/', RedirectView.as_view(url='https://www.djangoproject.com/'), name='go-to-django'),
]
 Attributes  
url  
The URL to redirect to, as a string. Or None to raise a 410 (Gone) HTTP error. 
  
pattern_name  
The name of the URL pattern to redirect to. Reversing will be done using the same args and kwargs as are passed in for this view. 
  
permanent  
Whether the redirect should be permanent. The only difference here is the HTTP status code returned. If True, then the redirect will use status code 301. If False, then the redirect will use status code 302. By default, permanent is False. 
  
query_string  
Whether to pass along the GET query string to the new location. If True, then the query string is appended to the URL. If False, then the query string is discarded. By default, query_string is False. 
 Methods  
get_redirect_url(*args, **kwargs)  
Constructs the target URL for redirection. The args and kwargs arguments are positional and/or keyword arguments captured from the URL pattern, respectively. The default implementation uses url as a starting string and performs expansion of % named parameters in that string using the named groups captured in the URL. If url is not set, get_redirect_url() tries to reverse the pattern_name using what was captured in the URL (both named and unnamed groups are used). If requested by query_string, it will also append the query string to the generated URL. Subclasses may implement any behavior they wish, as long as the method returns a redirect-ready URL string.
get_redirect_url(*args, **kwargs)  
Constructs the target URL for redirection. The args and kwargs arguments are positional and/or keyword arguments captured from the URL pattern, respectively. The default implementation uses url as a starting string and performs expansion of % named parameters in that string using the named groups captured in the URL. If url is not set, get_redirect_url() tries to reverse the pattern_name using what was captured in the URL (both named and unnamed groups are used). If requested by query_string, it will also append the query string to the generated URL. Subclasses may implement any behavior they wish, as long as the method returns a redirect-ready URL string.
pattern_name  
The name of the URL pattern to redirect to. Reversing will be done using the same args and kwargs as are passed in for this view.
permanent  
Whether the redirect should be permanent. The only difference here is the HTTP status code returned. If True, then the redirect will use status code 301. If False, then the redirect will use status code 302. By default, permanent is False.
query_string  
Whether to pass along the GET query string to the new location. If True, then the query string is appended to the URL. If False, then the query string is discarded. By default, query_string is False.
url  
The URL to redirect to, as a string. Or None to raise a 410 (Gone) HTTP error.
class django.views.generic.base.TemplateResponseMixin  
Provides a mechanism to construct a TemplateResponse, given suitable context. The template to use is configurable and can be further customized by subclasses. Attributes  
template_name  
The full name of a template to use as defined by a string. Not defining a template_name will raise a django.core.exceptions.ImproperlyConfigured exception. 
  
template_engine  
The NAME of a template engine to use for loading the template. template_engine is passed as the using keyword argument to response_class. Default is None, which tells Django to search for the template in all configured engines. 
  
response_class  
The response class to be returned by render_to_response method. Default is TemplateResponse. The template and context of TemplateResponse instances can be altered later (e.g. in template response middleware). If you need custom template loading or custom context object instantiation, create a TemplateResponse subclass and assign it to response_class. 
  
content_type  
The content type to use for the response. content_type is passed as a keyword argument to response_class. Default is None – meaning that Django uses 'text/html'. 
 Methods  
render_to_response(context, **response_kwargs)  
Returns a self.response_class instance. If any keyword arguments are provided, they will be passed to the constructor of the response class. Calls get_template_names() to obtain the list of template names that will be searched looking for an existent template. 
  
get_template_names()  
Returns a list of template names to search for when rendering the template. The first template that is found will be used. The default implementation will return a list containing template_name (if it is specified).
content_type  
The content type to use for the response. content_type is passed as a keyword argument to response_class. Default is None – meaning that Django uses 'text/html'.
get_template_names()  
Returns a list of template names to search for when rendering the template. The first template that is found will be used. The default implementation will return a list containing template_name (if it is specified).
render_to_response(context, **response_kwargs)  
Returns a self.response_class instance. If any keyword arguments are provided, they will be passed to the constructor of the response class. Calls get_template_names() to obtain the list of template names that will be searched looking for an existent template.
response_class  
The response class to be returned by render_to_response method. Default is TemplateResponse. The template and context of TemplateResponse instances can be altered later (e.g. in template response middleware). If you need custom template loading or custom context object instantiation, create a TemplateResponse subclass and assign it to response_class.
template_engine  
The NAME of a template engine to use for loading the template. template_engine is passed as the using keyword argument to response_class. Default is None, which tells Django to search for the template in all configured engines.
template_name  
The full name of a template to use as defined by a string. Not defining a template_name will raise a django.core.exceptions.ImproperlyConfigured exception.
class django.views.generic.base.TemplateView  
Renders a given template, with the context containing parameters captured in the URL. Ancestors (MRO) This view inherits methods and attributes from the following views:  django.views.generic.base.TemplateResponseMixin django.views.generic.base.ContextMixin django.views.generic.base.View  Method Flowchart  setup() dispatch() http_method_not_allowed() get_context_data()  Example views.py: from django.views.generic.base import TemplateView

from articles.models import Article

class HomePageView(TemplateView):

    template_name = "home.html"

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['latest_articles'] = Article.objects.all()[:5]
        return context
 Example urls.py: from django.urls import path

from myapp.views import HomePageView

urlpatterns = [
    path('', HomePageView.as_view(), name='home'),
]
 Context  Populated (through ContextMixin) with the keyword arguments captured from the URL pattern that served the view. You can also add context using the extra_context keyword argument for as_view().
class django.views.generic.base.View  
The master class-based base view. All other class-based views inherit from this base class. It isn’t strictly a generic view and thus can also be imported from django.views. Method Flowchart  setup() dispatch() http_method_not_allowed() options()  Example views.py: from django.http import HttpResponse
from django.views import View

class MyView(View):

    def get(self, request, *args, **kwargs):
        return HttpResponse('Hello, World!')
 Example urls.py: from django.urls import path

from myapp.views import MyView

urlpatterns = [
    path('mine/', MyView.as_view(), name='my-view'),
]
 Attributes  
http_method_names  
The list of HTTP method names that this view will accept. Default: ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace']
 
 Methods  
classmethod as_view(**initkwargs)  
Returns a callable view that takes a request and returns a response: response = MyView.as_view()(request)
 The returned view has view_class and view_initkwargs attributes. When the view is called during the request/response cycle, the setup() method assigns the HttpRequest to the view’s request attribute, and any positional and/or keyword arguments captured from the URL pattern to the args and kwargs attributes, respectively. Then dispatch() is called. 
  
setup(request, *args, **kwargs)  
Performs key view initialization prior to dispatch(). If overriding this method, you must call super(). 
  
dispatch(request, *args, **kwargs)  
The view part of the view – the method that accepts a request argument plus arguments, and returns an HTTP response. The default implementation will inspect the HTTP method and attempt to delegate to a method that matches the HTTP method; a GET will be delegated to get(), a POST to post(), and so on. By default, a HEAD request will be delegated to get(). If you need to handle HEAD requests in a different way than GET, you can override the head() method. See Supporting other HTTP methods for an example. 
  
http_method_not_allowed(request, *args, **kwargs)  
If the view was called with an HTTP method it doesn’t support, this method is called instead. The default implementation returns HttpResponseNotAllowed with a list of allowed methods in plain text. 
  
options(request, *args, **kwargs)  
Handles responding to requests for the OPTIONS HTTP verb. Returns a response with the Allow header containing a list of the view’s allowed HTTP method names.
dispatch(request, *args, **kwargs)  
The view part of the view – the method that accepts a request argument plus arguments, and returns an HTTP response. The default implementation will inspect the HTTP method and attempt to delegate to a method that matches the HTTP method; a GET will be delegated to get(), a POST to post(), and so on. By default, a HEAD request will be delegated to get(). If you need to handle HEAD requests in a different way than GET, you can override the head() method. See Supporting other HTTP methods for an example.
http_method_names  
The list of HTTP method names that this view will accept. Default: ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace']
http_method_not_allowed(request, *args, **kwargs)  
If the view was called with an HTTP method it doesn’t support, this method is called instead. The default implementation returns HttpResponseNotAllowed with a list of allowed methods in plain text.
options(request, *args, **kwargs)  
Handles responding to requests for the OPTIONS HTTP verb. Returns a response with the Allow header containing a list of the view’s allowed HTTP method names.
setup(request, *args, **kwargs)  
Performs key view initialization prior to dispatch(). If overriding this method, you must call super().
class ArchiveIndexView  
A top-level index page showing the “latest” objects, by date. Objects with a date in the future are not included unless you set allow_future to True. Ancestors (MRO)  django.views.generic.list.MultipleObjectTemplateResponseMixin django.views.generic.base.TemplateResponseMixin django.views.generic.dates.BaseArchiveIndexView django.views.generic.dates.BaseDateListView django.views.generic.list.MultipleObjectMixin django.views.generic.dates.DateMixin django.views.generic.base.View  Context In addition to the context provided by django.views.generic.list.MultipleObjectMixin (via django.views.generic.dates.BaseDateListView), the template’s context will be:  
date_list: A QuerySet object containing all years that have objects available according to queryset, represented as datetime.datetime objects, in descending order.  Notes  Uses a default context_object_name of latest. Uses a default template_name_suffix of _archive. Defaults to providing date_list by year, but this can be altered to month or day using the attribute date_list_period. This also applies to all subclass views.  Example myapp/urls.py: from django.urls import path
from django.views.generic.dates import ArchiveIndexView

from myapp.models import Article

urlpatterns = [
    path('archive/',
         ArchiveIndexView.as_view(model=Article, date_field="pub_date"),
         name="article_archive"),
]
 Example myapp/article_archive.html: <ul>
    {% for article in latest %}
        <li>{{ article.pub_date }}: {{ article.title }}</li>
    {% endfor %}
</ul>
 This will output all articles.
class BaseDateListView  
A base class that provides common behavior for all date-based views. There won’t normally be a reason to instantiate BaseDateListView; instantiate one of the subclasses instead. While this view (and its subclasses) are executing, self.object_list will contain the list of objects that the view is operating upon, and self.date_list will contain the list of dates for which data is available. Mixins  DateMixin MultipleObjectMixin  Methods and Attributes  
allow_empty  
A boolean specifying whether to display the page if no objects are available. If this is True and no objects are available, the view will display an empty page instead of raising a 404. This is identical to django.views.generic.list.MultipleObjectMixin.allow_empty, except for the default value, which is False. 
  
date_list_period  
Optional A string defining the aggregation period for date_list. It must be one of 'year' (default), 'month', or 'day'. 
  
get_dated_items()  
Returns a 3-tuple containing (date_list, object_list, extra_context). date_list is the list of dates for which data is available. object_list is the list of objects. extra_context is a dictionary of context data that will be added to any context data provided by the MultipleObjectMixin. 
  
get_dated_queryset(**lookup)  
Returns a queryset, filtered using the query arguments defined by lookup. Enforces any restrictions on the queryset, such as allow_empty and allow_future. 
  
get_date_list_period()  
Returns the aggregation period for date_list. Returns date_list_period by default. 
  
get_date_list(queryset, date_type=None, ordering='ASC')  
Returns the list of dates of type date_type for which queryset contains entries. For example, get_date_list(qs, 'year') will return the list of years for which qs has entries. If date_type isn’t provided, the result of get_date_list_period() is used. date_type and ordering are passed to QuerySet.dates().
allow_empty  
A boolean specifying whether to display the page if no objects are available. If this is True and no objects are available, the view will display an empty page instead of raising a 404. This is identical to django.views.generic.list.MultipleObjectMixin.allow_empty, except for the default value, which is False.
date_list_period  
Optional A string defining the aggregation period for date_list. It must be one of 'year' (default), 'month', or 'day'.
get_date_list(queryset, date_type=None, ordering='ASC')  
Returns the list of dates of type date_type for which queryset contains entries. For example, get_date_list(qs, 'year') will return the list of years for which qs has entries. If date_type isn’t provided, the result of get_date_list_period() is used. date_type and ordering are passed to QuerySet.dates().
get_date_list_period()  
Returns the aggregation period for date_list. Returns date_list_period by default.
get_dated_items()  
Returns a 3-tuple containing (date_list, object_list, extra_context). date_list is the list of dates for which data is available. object_list is the list of objects. extra_context is a dictionary of context data that will be added to any context data provided by the MultipleObjectMixin.
get_dated_queryset(**lookup)  
Returns a queryset, filtered using the query arguments defined by lookup. Enforces any restrictions on the queryset, such as allow_empty and allow_future.