doc_content
stringlengths
1
386k
doc_id
stringlengths
5
188
class Sitemap A Sitemap class can define the following methods/attributes: 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() ...
django.ref.contrib.sitemaps#django.contrib.sitemaps.Sitemap
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.
django.ref.contrib.sitemaps#django.contrib.sitemaps.Sitemap.alternates
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(). Possibl...
django.ref.contrib.sitemaps#django.contrib.sitemaps.Sitemap.changefreq
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.
django.ref.contrib.sitemaps#django.contrib.sitemaps.Sitemap.i18n
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.
django.ref.contrib.sitemaps#django.contrib.sitemaps.Sitemap.items
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.
django.ref.contrib.sitemaps#django.contrib.sitemaps.Sitemap.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 ...
django.ref.contrib.sitemaps#django.contrib.sitemaps.Sitemap.lastmod
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.
django.ref.contrib.sitemaps#django.contrib.sitemaps.Sitemap.limit
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...
django.ref.contrib.sitemaps#django.contrib.sitemaps.Sitemap.location
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.
django.ref.contrib.sitemaps#django.contrib.sitemaps.Sitemap.paginator
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 it...
django.ref.contrib.sitemaps#django.contrib.sitemaps.Sitemap.priority
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 si...
django.ref.contrib.sitemaps#django.contrib.sitemaps.Sitemap.protocol
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.
django.ref.contrib.sitemaps#django.contrib.sitemaps.Sitemap.x_default
views.index(request, sitemaps, template_name='sitemap_index.xml', content_type='application/xml', sitemap_url_name='django.contrib.sitemaps.views.sitemap')
django.ref.contrib.sitemaps#django.contrib.sitemaps.views.index
views.sitemap(request, sitemaps, section=None, template_name='sitemap.xml', content_type='application/xml')
django.ref.contrib.sitemaps#django.contrib.sitemaps.views.sitemap
class managers.CurrentSiteManager
django.ref.contrib.sites#django.contrib.sites.managers.CurrentSiteManager
class CurrentSiteMiddleware
django.ref.middleware#django.contrib.sites.middleware.CurrentSiteMiddleware
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.
django.ref.contrib.sites#django.contrib.sites.models.Site
domain The fully qualified domain name associated with the website. For example, www.example.com.
django.ref.contrib.sites#django.contrib.sites.models.Site.domain
name A human-readable “verbose” name for the website.
django.ref.contrib.sites#django.contrib.sites.models.Site.name
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().
django.ref.contrib.sites#django.contrib.sites.requests.RequestSite
__init__(request) Sets the name and domain attributes to the value of get_host().
django.ref.contrib.sites#django.contrib.sites.requests.RequestSite.__init__
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 retur...
django.ref.contrib.sites#django.contrib.sites.shortcuts.get_current_site
class storage.ManifestFilesMixin
django.ref.contrib.staticfiles#django.contrib.staticfiles.storage.ManifestFilesMixin
class storage.ManifestStaticFilesStorage
django.ref.contrib.staticfiles#django.contrib.staticfiles.storage.ManifestStaticFilesStorage
storage.ManifestStaticFilesStorage.file_hash(name, content=None)
django.ref.contrib.staticfiles#django.contrib.staticfiles.storage.ManifestStaticFilesStorage.file_hash
storage.ManifestStaticFilesStorage.manifest_strict
django.ref.contrib.staticfiles#django.contrib.staticfiles.storage.ManifestStaticFilesStorage.manifest_strict
storage.ManifestStaticFilesStorage.max_post_process_passes
django.ref.contrib.staticfiles#django.contrib.staticfiles.storage.ManifestStaticFilesStorage.max_post_process_passes
class storage.StaticFilesStorage
django.ref.contrib.staticfiles#django.contrib.staticfiles.storage.StaticFilesStorage
storage.StaticFilesStorage.post_process(paths, **options)
django.ref.contrib.staticfiles#django.contrib.staticfiles.storage.StaticFilesStorage.post_process
class testing.StaticLiveServerTestCase
django.ref.contrib.staticfiles#django.contrib.staticfiles.testing.StaticLiveServerTestCase
urls.staticfiles_urlpatterns()
django.ref.contrib.staticfiles#django.contrib.staticfiles.urls.staticfiles_urlpatterns
views.serve(request, path)
django.ref.contrib.staticfiles#django.contrib.staticfiles.views.serve
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 Articl...
django.ref.contrib.syndication#django.contrib.syndication.Feed.get_context_data
class views.Feed
django.ref.contrib.syndication#django.contrib.syndication.views.Feed
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 table...
django.topics.db.tablespaces
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...
django.topics.templates#django.template.backends.base.Template.render
class DjangoTemplates
django.topics.templates#django.template.backends.django.DjangoTemplates
class Jinja2
django.topics.templates#django.template.backends.jinja2.Jinja2
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 <unknow...
django.ref.templates.api#django.template.base.Origin
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.
django.ref.templates.api#django.template.base.Origin.loader
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>.
django.ref.templates.api#django.template.base.Origin.name
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.
django.ref.templates.api#django.template.base.Origin.template_name
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.
django.ref.templates.api#django.template.Context
Context.flatten()
django.ref.templates.api#django.template.Context.flatten
Context.get(key, otherwise=None) Returns the value for key if key is in the context, else returns otherwise.
django.ref.templates.api#django.template.Context.get
Context.pop()
django.ref.templates.api#django.template.Context.pop
Context.push()
django.ref.templates.api#django.template.Context.push
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.
django.ref.templates.api#django.template.Context.setdefault
Context.update(other_dict)
django.ref.templates.api#django.template.Context.update
debug()
django.ref.templates.api#django.template.context_processors.debug
i18n()
django.ref.templates.api#django.template.context_processors.i18n
static()
django.ref.templates.api#django.template.context_processors.static
tz()
django.ref.templates.api#django.template.context_processors.tz
django.template.defaultfilters.stringfilter()
django.howto.custom-template-tags#django.template.defaultfilters.stringfilter
class Engine(dirs=None, app_dirs=False, context_processors=None, debug=False, loaders=None, string_if_invalid='', file_charset='utf-8', libraries=None, builtins=None, autoescape=True) When instantiating an Engine all arguments must be passed as keyword arguments: dirs is a list of directories where the engine shoul...
django.ref.templates.api#django.template.Engine
Engine.from_string(template_code) Compiles the given template code and returns a Template object.
django.ref.templates.api#django.template.Engine.from_string
Engine.get_template(template_name) Loads a template with the given name, compiles it and returns a Template object.
django.ref.templates.api#django.template.Engine.get_template
Engine.select_template(template_name_list) Like get_template(), except it takes a list of names and returns the first template that was found.
django.ref.templates.api#django.template.Engine.select_template
django.template.Library.filter()
django.howto.custom-template-tags#django.template.Library.filter
django.template.Library.inclusion_tag()
django.howto.custom-template-tags#django.template.Library.inclusion_tag
django.template.Library.simple_tag()
django.howto.custom-template-tags#django.template.Library.simple_tag
engines Template engines are available in django.template.engines: from django.template import engines django_engine = engines['django'] template = django_engine.from_string("Hello {{ name }}!") The lookup key — 'django' in this example — is the engine’s NAME.
django.topics.templates#django.template.loader.engines
get_template(template_name, using=None) This function loads the template with the given name and returns a Template object. The exact type of the return value depends on the backend that loaded the template. Each backend has its own Template class. get_template() tries each template engine in order until one succeeds...
django.topics.templates#django.template.loader.get_template
render_to_string(template_name, context=None, request=None, using=None) render_to_string() loads a template like get_template() and calls its render() method immediately. It takes the following arguments. template_name The name of the template to load and render. If it’s a list of template names, Django uses selec...
django.topics.templates#django.template.loader.render_to_string
select_template(template_name_list, using=None) select_template() is just like get_template(), except it takes a list of template names. It tries each name in order and returns the first template that exists.
django.topics.templates#django.template.loader.select_template
class app_directories.Loader Loads templates from Django apps on the filesystem. For each app in INSTALLED_APPS, the loader looks for a templates subdirectory. If the directory exists, Django looks for templates in there. This means you can store templates with your individual apps. This also helps to distribute Djan...
django.ref.templates.api#django.template.loaders.app_directories.Loader
class Loader Loads templates from a given source, such as the filesystem or a database. get_template_sources(template_name) A method that takes a template_name and yields Origin instances for each possible source. For example, the filesystem loader may receive 'index.html' as a template_name argument. This method...
django.ref.templates.api#django.template.loaders.base.Loader
get_contents(origin) Returns the contents for a template given a Origin instance. This is where a filesystem loader would read contents from the filesystem, or a database loader would read from the database. If a matching template doesn’t exist, this should raise a TemplateDoesNotExist error.
django.ref.templates.api#django.template.loaders.base.Loader.get_contents
get_template(template_name, skip=None) Returns a Template object for a given template_name by looping through results from get_template_sources() and calling get_contents(). This returns the first matching template. If no template is found, TemplateDoesNotExist is raised. The optional skip argument is a list of origi...
django.ref.templates.api#django.template.loaders.base.Loader.get_template
get_template_sources(template_name) A method that takes a template_name and yields Origin instances for each possible source. For example, the filesystem loader may receive 'index.html' as a template_name argument. This method would yield origins for the full path of index.html as it appears in each template director...
django.ref.templates.api#django.template.loaders.base.Loader.get_template_sources
class cached.Loader By default (when DEBUG is True), the template system reads and compiles your templates every time they’re rendered. While the Django template system is quite fast, the overhead from reading and compiling templates can add up. You configure the cached template loader with a list of other loaders th...
django.ref.templates.api#django.template.loaders.cached.Loader
class filesystem.Loader Loads templates from the filesystem, according to DIRS. This loader is enabled by default. However it won’t find any templates until you set DIRS to a non-empty list: TEMPLATES = [{ 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [BASE_DIR / 'templates'], }] You ...
django.ref.templates.api#django.template.loaders.filesystem.Loader
class locmem.Loader Loads templates from a Python dictionary. This is useful for testing. This loader takes a dictionary of templates as its first argument: TEMPLATES = [{ 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'OPTIONS': { 'loaders': [ ('django.template.loaders.locm...
django.ref.templates.api#django.template.loaders.locmem.Loader
class RequestContext(request, dict_=None, processors=None)
django.ref.templates.api#django.template.RequestContext
class SimpleTemplateResponse
django.ref.template-response#django.template.response.SimpleTemplateResponse
SimpleTemplateResponse.__init__(template, context=None, content_type=None, status=None, charset=None, using=None, headers=None) Instantiates a SimpleTemplateResponse object with the given template, context, content type, HTTP status, and charset. template A backend-dependent template object (such as those returned...
django.ref.template-response#django.template.response.SimpleTemplateResponse.__init__
SimpleTemplateResponse.add_post_render_callback() Add a callback that will be invoked after rendering has taken place. This hook can be used to defer certain processing operations (such as caching) until after rendering has occurred. If the SimpleTemplateResponse has already been rendered, the callback will be invoke...
django.ref.template-response#django.template.response.SimpleTemplateResponse.add_post_render_callback
SimpleTemplateResponse.context_data The context data to be used when rendering the template. It must be a dict. Example: {'foo': 123}
django.ref.template-response#django.template.response.SimpleTemplateResponse.context_data
SimpleTemplateResponse.is_rendered A boolean indicating whether the response content has been rendered.
django.ref.template-response#django.template.response.SimpleTemplateResponse.is_rendered
SimpleTemplateResponse.render() Sets response.content to the result obtained by SimpleTemplateResponse.rendered_content, runs all post-rendering callbacks, and returns the resulting response object. render() will only have an effect the first time it is called. On subsequent calls, it will return the result obtained ...
django.ref.template-response#django.template.response.SimpleTemplateResponse.render
SimpleTemplateResponse.rendered_content The current rendered value of the response content, using the current template and context data.
django.ref.template-response#django.template.response.SimpleTemplateResponse.rendered_content
SimpleTemplateResponse.resolve_context(context) Preprocesses context data that will be used for rendering a template. Accepts a dict of context data. By default, returns the same dict. Override this method in order to customize the context.
django.ref.template-response#django.template.response.SimpleTemplateResponse.resolve_context
SimpleTemplateResponse.resolve_template(template) Resolves the template instance to use for rendering. Accepts a backend-dependent template object (such as those returned by get_template()), the name of a template, or a list of template names. Returns the backend-dependent template object instance to be rendered. Ove...
django.ref.template-response#django.template.response.SimpleTemplateResponse.resolve_template
SimpleTemplateResponse.template_name The name of the template to be rendered. Accepts a backend-dependent template object (such as those returned by get_template()), the name of a template, or a list of template names. Example: ['foo.html', 'path/to/bar.html']
django.ref.template-response#django.template.response.SimpleTemplateResponse.template_name
class TemplateResponse TemplateResponse is a subclass of SimpleTemplateResponse that knows about the current HttpRequest.
django.ref.template-response#django.template.response.TemplateResponse
TemplateResponse.__init__(request, template, context=None, content_type=None, status=None, charset=None, using=None, headers=None) Instantiates a TemplateResponse object with the given request, template, context, content type, HTTP status, and charset. request An HttpRequest instance. template A backend-dependen...
django.ref.template-response#django.template.response.TemplateResponse.__init__
class Template This class lives at django.template.Template. The constructor takes one argument — the raw template code: from django.template import Template template = Template("My name is {{ my_name }}.")
django.ref.templates.api#django.template.Template
Template.render(context) Call the Template object’s render() method with a Context to “fill” the template: >>> from django.template import Context, Template >>> template = Template("My name is {{ my_name }}.") >>> context = Context({"my_name": "Adrian"}) >>> template.render(context) "My name is Adrian." >>> context...
django.ref.templates.api#django.template.Template.render
Templates Django’s template engine provides a powerful mini-language for defining the user-facing layer of your application, encouraging a clean separation of application and presentation logic. Templates can be maintained by anyone with an understanding of HTML; no knowledge of Python is required. For introductory mat...
django.ref.templates.index
Templates Being a web framework, Django needs a convenient way to generate HTML dynamically. The most common approach relies on templates. A template contains the static parts of the desired HTML output as well as some special syntax describing how dynamic content will be inserted. For a hands-on example of creating HT...
django.topics.templates
class Client(enforce_csrf_checks=False, json_encoder=DjangoJSONEncoder, **defaults) It requires no arguments at time of construction. However, you can use keyword arguments to specify some default headers. For example, this will send a User-Agent HTTP header in each request: >>> c = Client(HTTP_USER_AGENT='Mozilla/5....
django.topics.testing.tools#django.test.Client
Client.cookies A Python SimpleCookie object, containing the current values of all the client cookies. See the documentation of the http.cookies module for more.
django.topics.testing.tools#django.test.Client.cookies
delete(path, data='', content_type='application/octet-stream', follow=False, secure=False, **extra) Makes a DELETE request on the provided path and returns a Response object. Useful for testing RESTful interfaces. When data is provided, it is used as the request body, and a Content-Type header is set to content_type....
django.topics.testing.tools#django.test.Client.delete
force_login(user, backend=None) If your site uses Django’s authentication system, you can use the force_login() method to simulate the effect of a user logging into the site. Use this method instead of login() when a test requires a user be logged in and the details of how a user logged in aren’t important. Unlike lo...
django.topics.testing.tools#django.test.Client.force_login
get(path, data=None, follow=False, secure=False, **extra) Makes a GET request on the provided path and returns a Response object, which is documented below. The key-value pairs in the data dictionary are used to create a GET data payload. For example: >>> c = Client() >>> c.get('/customers/details/', {'name': 'fred',...
django.topics.testing.tools#django.test.Client.get
head(path, data=None, follow=False, secure=False, **extra) Makes a HEAD request on the provided path and returns a Response object. This method works just like Client.get(), including the follow, secure and extra arguments, except it does not return a message body.
django.topics.testing.tools#django.test.Client.head
login(**credentials) If your site uses Django’s authentication system and you deal with logging in users, you can use the test client’s login() method to simulate the effect of a user logging into the site. After you call this method, the test client will have all the cookies and session data required to pass any log...
django.topics.testing.tools#django.test.Client.login
logout() If your site uses Django’s authentication system, the logout() method can be used to simulate the effect of a user logging out of your site. After you call this method, the test client will have all the cookies and session data cleared to defaults. Subsequent requests will appear to come from an AnonymousUse...
django.topics.testing.tools#django.test.Client.logout
options(path, data='', content_type='application/octet-stream', follow=False, secure=False, **extra) Makes an OPTIONS request on the provided path and returns a Response object. Useful for testing RESTful interfaces. When data is provided, it is used as the request body, and a Content-Type header is set to content_ty...
django.topics.testing.tools#django.test.Client.options