neulab/docprompting-conala huggingface dataset:
class models.Redirect  
Redirects are represented by a standard Django model, which lives in django/contrib/redirects/models.py. You can access redirect objects via the Django database API. For example: >>> from django.conf import settings
>>> from django.contrib.redirects.models import Redirect
>>> # Add a new redirect.
>>> redirect = Redirect.objects.create(
...     site_id=1,
...     old_path='/contact-us/',
...     new_path='/contact/',
... )
>>> # Change a redirect.
>>> redirect.new_path = '/contact-details/'
>>> redirect.save()
>>> redirect
<Redirect: /contact-us/ ---> /contact-details/>
>>> # Delete a redirect.
>>> Redirect.objects.filter(site_id=1, old_path='/contact-us/').delete()
(1, {'redirects.Redirect': 1})
__delitem__(key)  
Example: del request.session['fav_color']. This raises KeyError if the given key isn’t already in the session.
__getitem__(key)  
Example: fav_color = request.session['fav_color']
__setitem__(key, value)  
Example: request.session['fav_color'] = 'blue'
clear_expired()  
Removes expired sessions from the session store. This class method is called by clearsessions.
cycle_key()  
Creates a new session key while retaining the current session data. django.contrib.auth.login() calls this method to mitigate against session fixation.
delete_test_cookie()  
Deletes the test cookie. Use this to clean up after yourself.
flush()  
Deletes the current session data from the session and deletes the session cookie. This is used if you want to ensure that the previous session data can’t be accessed again from the user’s browser (for example, the django.contrib.auth.logout() function calls it).
get(key, default=None)  
Example: fav_color = request.session.get('fav_color', 'red')
get_expire_at_browser_close()  
Returns either True or False, depending on whether the user’s session cookie will expire when the user’s web browser is closed.
get_expiry_age()  
Returns the number of seconds until this session expires. For sessions with no custom expiration (or those set to expire at browser close), this will equal SESSION_COOKIE_AGE. This function accepts two optional keyword arguments:  
modification: last modification of the session, as a datetime object. Defaults to the current time. 
expiry: expiry information for the session, as a datetime object, an int (in seconds), or None. Defaults to the value stored in the session by set_expiry(), if there is one, or None.
get_expiry_date()  
Returns the date this session will expire. For sessions with no custom expiration (or those set to expire at browser close), this will equal the date SESSION_COOKIE_AGE seconds from now. This function accepts the same keyword arguments as get_expiry_age().
get_session_cookie_age()  
Returns the age of session cookies, in seconds. Defaults to SESSION_COOKIE_AGE.
pop(key, default=__not_given)  
Example: fav_color = request.session.pop('fav_color', 'blue')
set_expiry(value)  
Sets the expiration time for the session. You can pass a number of different values:  If value is an integer, the session will expire after that many seconds of inactivity. For example, calling request.session.set_expiry(300) would make the session expire in 5 minutes. If value is a datetime or timedelta object, the session will expire at that specific date/time. Note that datetime and timedelta values are only serializable if you are using the PickleSerializer. If value is 0, the user’s session cookie will expire when the user’s web browser is closed. If value is None, the session reverts to using the global session expiry policy.  Reading a session is not considered activity for expiration purposes. Session expiration is computed from the last time the session was modified.
set_test_cookie()  
Sets a test cookie to determine whether the user’s browser supports cookies. Due to the way cookies work, you won’t be able to test this until the user’s next page request. See Setting test cookies below for more information.
test_cookie_worked()  
Returns either True or False, depending on whether the user’s browser accepted the test cookie. Due to the way cookies work, you’ll have to call set_test_cookie() on a previous, separate page request. See Setting test cookies below for more information.
class backends.cached_db.SessionStore  
Implements cached database-backed session store.  
cache_key_prefix  
A prefix added to a session key to build a cache key string.
cache_key_prefix  
A prefix added to a session key to build a cache key string.
class backends.db.SessionStore  
Implements database-backed session store.  
classmethod get_model_class()  
Override this method to return a custom session model if you need one. 
  
create_model_instance(data)  
Returns a new instance of the session model object, which represents the current session state. Overriding this method provides the ability to modify session model data before it’s saved to database.
create_model_instance(data)  
Returns a new instance of the session model object, which represents the current session state. Overriding this method provides the ability to modify session model data before it’s saved to database.
class base_session.AbstractBaseSession  
The abstract base session model.  
session_key  
Primary key. The field itself may contain up to 40 characters. The current implementation generates a 32-character string (a random sequence of digits and lowercase ASCII letters). 
  
session_data  
A string containing an encoded and serialized session dictionary. 
  
expire_date  
A datetime designating when the session expires. Expired sessions are not available to a user, however, they may still be stored in the database until the clearsessions management command is run. 
  
classmethod get_session_store_class()  
Returns a session store class to be used with this session model. 
  
get_decoded()  
Returns decoded session data. Decoding is performed by the session store class.
expire_date  
A datetime designating when the session expires. Expired sessions are not available to a user, however, they may still be stored in the database until the clearsessions management command is run.
get_decoded()  
Returns decoded session data. Decoding is performed by the session store class.
session_key  
Primary key. The field itself may contain up to 40 characters. The current implementation generates a 32-character string (a random sequence of digits and lowercase ASCII letters).
class base_session.BaseSessionManager  
 
encode(session_dict)  
Returns the given session dictionary serialized and encoded as a string. Encoding is performed by the session store class tied to a model class. 
  
save(session_key, session_dict, expire_date)  
Saves session data for a provided session key, or deletes the session in case the data is empty.
encode(session_dict)  
Returns the given session dictionary serialized and encoded as a string. Encoding is performed by the session store class tied to a model class.
save(session_key, session_dict, expire_date)  
Saves session data for a provided session key, or deletes the session in case the data is empty.
class serializers.JSONSerializer  
A wrapper around the JSON serializer from django.core.signing. Can only serialize basic data types. In addition, as JSON supports only string keys, note that using non-string keys in request.session won’t work as expected: >>> # initial assignment
>>> request.session[0] = 'bar'
>>> # subsequent requests following serialization & deserialization
>>> # of session data
>>> request.session[0]  # KeyError
>>> request.session['0']
'bar'
 Similarly, data that can’t be encoded in JSON, such as non-UTF8 bytes like '\xd9' (which raises UnicodeDecodeError), can’t be stored. See the Write your own serializer section for more details on limitations of JSON serialization.
class serializers.PickleSerializer  
Supports arbitrary Python objects, but, as described above, can lead to a remote code execution vulnerability if SECRET_KEY becomes known by an attacker.
setup(set_prefix=True) [source]
 
Configures Django by:  Loading the settings. Setting up logging. If set_prefix is True, setting the URL resolver script prefix to FORCE_SCRIPT_NAME if defined, or / otherwise. Initializing the application registry.  This function is called automatically:  When running an HTTP server via Django’s WSGI support. When invoking a management command.  It must be called explicitly in other cases, for instance in plain Python scripts.
get_list_or_404(klass, *args, **kwargs)  
Returns the result of filter() on a given model manager cast to a list, raising Http404 if the resulting list is empty.
get_object_or_404(klass, *args, **kwargs)  
Calls get() on a given model manager, but it raises Http404 instead of the model’s DoesNotExist exception.
redirect(to, *args, permanent=False, **kwargs)  
Returns an HttpResponseRedirect to the appropriate URL for the arguments passed. The arguments could be:  A model: the model’s get_absolute_url() function will be called. A view name, possibly with arguments: reverse() will be used to reverse-resolve the name. An absolute or relative URL, which will be used as-is for the redirect location.  By default issues a temporary redirect; pass permanent=True to issue a permanent redirect.
render(request, template_name, context=None, content_type=None, status=None, using=None)  
Combines a given template with a given context dictionary and returns an HttpResponse object with that rendered text. Django does not provide a shortcut function which returns a TemplateResponse because the constructor of TemplateResponse offers the same level of convenience as render().
class GenericSitemap(info_dict, priority=None, changefreq=None, protocol=None)  
The django.contrib.sitemaps.GenericSitemap class allows you to create a sitemap by passing it a dictionary which has to contain at least a queryset entry. This queryset will be used to generate the items of the sitemap. It may also have a date_field entry that specifies a date field for objects retrieved from the queryset. This will be used for the lastmod attribute in the generated sitemap. The priority, changefreq, and protocol keyword arguments allow specifying these attributes for all URLs.
ping_google(sitemap_url=None, ping_url=PING_URL, sitemap_uses_https=True)  
ping_google takes these optional arguments:  
sitemap_url - The absolute path to your site’s sitemap (e.g., '/sitemap.xml'). If this argument isn’t provided, ping_google will perform a reverse lookup in your URLconf, for URLs named 'django.contrib.sitemaps.views.index' and then 'django.contrib.sitemaps.views.sitemap' (without further arguments) to automatically determine the sitemap URL.  
ping_url - Defaults to Google’s Ping Tool: https://www.google.com/webmasters/tools/ping.  
sitemap_uses_https - Set to False if your site uses http rather than https.   ping_google() raises the exception django.contrib.sitemaps.SitemapNotFound if it cannot determine your sitemap URL.
alternates  
 New in Django 3.2.  Optional. A boolean attribute. When used in conjunction with i18n generated URLs will each have a list of alternate links pointing to other language versions using the hreflang attribute. The default is False.
changefreq  
Optional. Either a method or attribute. If it’s a method, it should take one argument – an object as returned by items() – and return that object’s change frequency as a string. If it’s an attribute, its value should be a string representing the change frequency of every object returned by items(). Possible values for changefreq, whether you use a method or attribute, are:  'always' 'hourly' 'daily' 'weekly' 'monthly' 'yearly' 'never'
i18n  
Optional. A boolean attribute that defines if the URLs of this sitemap should be generated using all of your LANGUAGES. The default is False.
items  
Required. A method that returns a sequence or QuerySet of objects. The framework doesn’t care what type of objects they are; all that matters is that these objects get passed to the location(), lastmod(), changefreq() and priority() methods.
languages  
 New in Django 3.2.  Optional. A sequence of language codes to use for generating alternate links when i18n is enabled. Defaults to LANGUAGES.
lastmod  
Optional. Either a method or attribute. If it’s a method, it should take one argument – an object as returned by items() – and return that object’s last-modified date/time as a datetime. If it’s an attribute, its value should be a datetime representing the last-modified date/time for every object returned by items(). If all items in a sitemap have a lastmod, the sitemap generated by views.sitemap() will have a Last-Modified header equal to the latest lastmod. You can activate the ConditionalGetMiddleware to make Django respond appropriately to requests with an If-Modified-Since header which will prevent sending the sitemap if it hasn’t changed.
limit  
Optional. This attribute defines the maximum number of URLs included on each page of the sitemap. Its value should not exceed the default value of 50000, which is the upper limit allowed in the Sitemaps protocol.
location  
Optional. Either a method or attribute. If it’s a method, it should return the absolute path for a given object as returned by items(). If it’s an attribute, its value should be a string representing an absolute path to use for every object returned by items(). In both cases, “absolute path” means a URL that doesn’t include the protocol or domain. Examples:  Good: '/foo/bar/'
 Bad: 'example.com/foo/bar/'
 Bad: 'https://example.com/foo/bar/'
  If location isn’t provided, the framework will call the get_absolute_url() method on each object as returned by items(). To specify a protocol other than 'http', use protocol.
paginator  
Optional. This property returns a Paginator for items(). If you generate sitemaps in a batch you may want to override this as a cached property in order to avoid multiple items() calls.
priority  
Optional. Either a method or attribute. If it’s a method, it should take one argument – an object as returned by items() – and return that object’s priority as either a string or float. If it’s an attribute, its value should be either a string or float representing the priority of every object returned by items(). Example values for priority: 0.4, 1.0. The default priority of a page is 0.5. See the sitemaps.org documentation for more.
protocol  
Optional. This attribute defines the protocol ('http' or 'https') of the URLs in the sitemap. If it isn’t set, the protocol with which the sitemap was requested is used. If the sitemap is built outside the context of a request, the default is 'http'.  Deprecated since version 4.0: The default protocol for sitemaps built outside the context of a request will change from 'http' to 'https' in Django 5.0.
x_default  
 New in Django 3.2.  Optional. A boolean attribute. When True the alternate links generated by alternates will contain a hreflang="x-default" fallback entry with a value of LANGUAGE_CODE. The default is False.
views.index(request, sitemaps, template_name='sitemap_index.xml', content_type='application/xml', sitemap_url_name='django.contrib.sitemaps.views.sitemap')
views.sitemap(request, sitemaps, section=None, template_name='sitemap.xml', content_type='application/xml')
class models.Site  
A model for storing the domain and name attributes of a website.  
domain  
The fully qualified domain name associated with the website. For example, www.example.com. 
  
name  
A human-readable “verbose” name for the website.
domain  
The fully qualified domain name associated with the website. For example, www.example.com.
class requests.RequestSite  
A class that shares the primary interface of Site (i.e., it has domain and name attributes) but gets its data from a Django HttpRequest object rather than from a database.  
__init__(request)  
Sets the name and domain attributes to the value of get_host().
__init__(request)  
Sets the name and domain attributes to the value of get_host().
shortcuts.get_current_site(request)  
A function that checks if django.contrib.sites is installed and returns either the current Site object or a RequestSite object based on the request. It looks up the current site based on request.get_host() if the SITE_ID setting is not defined. Both a domain and a port may be returned by request.get_host() when the Host header has a port explicitly specified, e.g. example.com:80. In such cases, if the lookup fails because the host does not match a record in the database, the port is stripped and the lookup is retried with the domain part only. This does not apply to RequestSite which will always use the unmodified host.
storage.ManifestStaticFilesStorage.file_hash(name, content=None)
Feed.get_context_data(**kwargs)  
There is also a way to pass additional information to title and description templates, if you need to supply more than the two variables mentioned before. You can provide your implementation of get_context_data method in your Feed subclass. For example: from mysite.models import Article
from django.contrib.syndication.views import Feed

class ArticlesFeed(Feed):
    title = "My articles"
    description_template = "feeds/articles.html"

    def items(self):
        return Article.objects.order_by('-pub_date')[:5]

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['foo'] = 'bar'
        return context
Tablespaces A common paradigm for optimizing performance in database systems is the use of tablespaces to organize disk layout.  Warning Django does not create the tablespaces for you. Please refer to your database engine’s documentation for details on creating and managing tablespaces.  Declaring tablespaces for tables A tablespace can be specified for the table generated by a model by supplying the db_tablespace option inside the model’s class Meta. This option also affects tables automatically created for ManyToManyFields in the model. You can use the DEFAULT_TABLESPACE setting to specify a default value for db_tablespace. This is useful for setting a tablespace for the built-in Django apps and other applications whose code you cannot control. Declaring tablespaces for indexes You can pass the db_tablespace option to an Index constructor to specify the name of a tablespace to use for the index. For single field indexes, you can pass the db_tablespace option to a Field constructor to specify an alternate tablespace for the field’s column index. If the column doesn’t have an index, the option is ignored. You can use the DEFAULT_INDEX_TABLESPACE setting to specify a default value for db_tablespace. If db_tablespace isn’t specified and you didn’t set DEFAULT_INDEX_TABLESPACE, the index is created in the same tablespace as the tables. An example class TablespaceExample(models.Model):
    name = models.CharField(max_length=30, db_index=True, db_tablespace="indexes")
    data = models.CharField(max_length=255, db_index=True)
    shortcut = models.CharField(max_length=7)
    edges = models.ManyToManyField(to="self", db_tablespace="indexes")

    class Meta:
        db_tablespace = "tables"
        indexes = [models.Index(fields=['shortcut'], db_tablespace='other_indexes')]
 In this example, the tables generated by the TablespaceExample model (i.e. the model table and the many-to-many table) would be stored in the tables tablespace. The index for the name field and the indexes on the many-to-many table would be stored in the indexes tablespace. The data field would also generate an index, but no tablespace for it is specified, so it would be stored in the model tablespace tables by default. The index for the shortcut field would be stored in the other_indexes tablespace. Database support PostgreSQL and Oracle support tablespaces. SQLite, MariaDB and MySQL don’t. When you use a backend that lacks support for tablespaces, Django ignores all tablespace-related options.
Template.render(context=None, request=None)  
Renders this template with a given context. If context is provided, it must be a dict. If it isn’t provided, the engine will render the template with an empty context. If request is provided, it must be an HttpRequest. Then the engine must make it, as well as the CSRF token, available in the template. How this is achieved is up to each backend.
class Origin(name, template_name=None, loader=None)  
 
name  
The path to the template as returned by the template loader. For loaders that read from the file system, this is the full path to the template. If the template is instantiated directly rather than through a template loader, this is a string value of <unknown_source>. 
  
template_name  
The relative path to the template as passed into the template loader. If the template is instantiated directly rather than through a template loader, this is None. 
  
loader  
The template loader instance that constructed this Origin. If the template is instantiated directly rather than through a template loader, this is None. django.template.loaders.cached.Loader requires all of its wrapped loaders to set this attribute, typically by instantiating the Origin with loader=self.
loader  
The template loader instance that constructed this Origin. If the template is instantiated directly rather than through a template loader, this is None. django.template.loaders.cached.Loader requires all of its wrapped loaders to set this attribute, typically by instantiating the Origin with loader=self.
name  
The path to the template as returned by the template loader. For loaders that read from the file system, this is the full path to the template. If the template is instantiated directly rather than through a template loader, this is a string value of <unknown_source>.
template_name  
The relative path to the template as passed into the template loader. If the template is instantiated directly rather than through a template loader, this is None.
class Context(dict_=None)  
The constructor of django.template.Context takes an optional argument — a dictionary mapping variable names to variable values. For details, see Playing with Context objects below.
Context.get(key, otherwise=None)  
Returns the value for key if key is in the context, else returns otherwise.
Context.setdefault(key, default=None)  
If key is in the context, returns its value. Otherwise inserts key with a value of default and returns default.