doc_content
stringlengths
1
386k
doc_id
stringlengths
5
188
HttpResponse.seekable() Always False. This method makes an HttpResponse instance a stream-like object.
django.ref.request-response#django.http.HttpResponse.seekable
HttpResponse.set_cookie(key, value='', max_age=None, expires=None, path='/', domain=None, secure=False, httponly=False, samesite=None) Sets a cookie. The parameters are the same as in the Morsel cookie object in the Python standard library. max_age should be an integer number of seconds, or None (default) if the co...
django.ref.request-response#django.http.HttpResponse.set_cookie
HttpResponse.set_signed_cookie(key, value, salt='', max_age=None, expires=None, path='/', domain=None, secure=False, httponly=False, samesite=None) Like set_cookie(), but cryptographic signing the cookie before setting it. Use in conjunction with HttpRequest.get_signed_cookie(). You can use the optional salt argument...
django.ref.request-response#django.http.HttpResponse.set_signed_cookie
HttpResponse.setdefault(header, value) Sets a header unless it has already been set.
django.ref.request-response#django.http.HttpResponse.setdefault
HttpResponse.status_code The HTTP status code for the response. Unless reason_phrase is explicitly set, modifying the value of status_code outside the constructor will also modify the value of reason_phrase.
django.ref.request-response#django.http.HttpResponse.status_code
HttpResponse.streaming This is always False. This attribute exists so middleware can treat streaming responses differently from regular responses.
django.ref.request-response#django.http.HttpResponse.streaming
HttpResponse.tell() This method makes an HttpResponse instance a file-like object.
django.ref.request-response#django.http.HttpResponse.tell
HttpResponse.writable() Always True. This method makes an HttpResponse instance a stream-like object.
django.ref.request-response#django.http.HttpResponse.writable
HttpResponse.write(content) This method makes an HttpResponse instance a file-like object.
django.ref.request-response#django.http.HttpResponse.write
HttpResponse.writelines(lines) Writes a list of lines to the response. Line separators are not added. This method makes an HttpResponse instance a stream-like object.
django.ref.request-response#django.http.HttpResponse.writelines
class HttpResponseBadRequest Acts just like HttpResponse but uses a 400 status code.
django.ref.request-response#django.http.HttpResponseBadRequest
class HttpResponseForbidden Acts just like HttpResponse but uses a 403 status code.
django.ref.request-response#django.http.HttpResponseForbidden
class HttpResponseGone Acts just like HttpResponse but uses a 410 status code.
django.ref.request-response#django.http.HttpResponseGone
class HttpResponseNotAllowed Like HttpResponse, but uses a 405 status code. The first argument to the constructor is required: a list of permitted methods (e.g. ['GET', 'POST']).
django.ref.request-response#django.http.HttpResponseNotAllowed
class HttpResponseNotFound Acts just like HttpResponse but uses a 404 status code.
django.ref.request-response#django.http.HttpResponseNotFound
class HttpResponseNotModified The constructor doesn’t take any arguments and no content should be added to this response. Use this to designate that a page hasn’t been modified since the user’s last request (status code 304).
django.ref.request-response#django.http.HttpResponseNotModified
class HttpResponsePermanentRedirect Like HttpResponseRedirect, but it returns a permanent redirect (HTTP status code 301) instead of a “found” redirect (status code 302).
django.ref.request-response#django.http.HttpResponsePermanentRedirect
class HttpResponseRedirect The first argument to the constructor is required – the path to redirect to. This can be a fully qualified URL (e.g. 'https://www.yahoo.com/search/'), an absolute path with no domain (e.g. '/search/'), or even a relative path (e.g. 'search/'). In that last case, the client browser will reco...
django.ref.request-response#django.http.HttpResponseRedirect
url This read-only attribute represents the URL the response will redirect to (equivalent to the Location response header).
django.ref.request-response#django.http.HttpResponseRedirect.url
class HttpResponseServerError Acts just like HttpResponse but uses a 500 status code.
django.ref.request-response#django.http.HttpResponseServerError
class JsonResponse(data, encoder=DjangoJSONEncoder, safe=True, json_dumps_params=None, **kwargs) An HttpResponse subclass that helps to create a JSON-encoded response. It inherits most behavior from its superclass with a couple differences: Its default Content-Type header is set to application/json. The first paramet...
django.ref.request-response#django.http.JsonResponse
class QueryDict
django.ref.request-response#django.http.QueryDict
QueryDict.__contains__(key) Returns True if the given key is set. This lets you do, e.g., if "foo" in request.GET.
django.ref.request-response#django.http.QueryDict.__contains__
QueryDict.__getitem__(key) Returns the value for the given key. If the key has more than one value, it returns the last value. Raises django.utils.datastructures.MultiValueDictKeyError if the key does not exist. (This is a subclass of Python’s standard KeyError, so you can stick to catching KeyError.)
django.ref.request-response#django.http.QueryDict.__getitem__
QueryDict.__init__(query_string=None, mutable=False, encoding=None) Instantiates a QueryDict object based on query_string. >>> QueryDict('a=1&a=2&c=3') <QueryDict: {'a': ['1', '2'], 'c': ['3']}> If query_string is not passed in, the resulting QueryDict will be empty (it will have no keys or values). Most QueryDicts ...
django.ref.request-response#django.http.QueryDict.__init__
QueryDict.__setitem__(key, value) Sets the given key to [value] (a list whose single element is value). Note that this, as other dictionary functions that have side effects, can only be called on a mutable QueryDict (such as one that was created via QueryDict.copy()).
django.ref.request-response#django.http.QueryDict.__setitem__
QueryDict.appendlist(key, item) Appends an item to the internal list associated with key.
django.ref.request-response#django.http.QueryDict.appendlist
QueryDict.copy() Returns a copy of the object using copy.deepcopy(). This copy will be mutable even if the original was not.
django.ref.request-response#django.http.QueryDict.copy
QueryDict.dict() Returns a dict representation of QueryDict. For every (key, list) pair in QueryDict, dict will have (key, item), where item is one element of the list, using the same logic as QueryDict.__getitem__(): >>> q = QueryDict('a=1&a=3&a=5') >>> q.dict() {'a': '5'}
django.ref.request-response#django.http.QueryDict.dict
QueryDict.get(key, default=None) Uses the same logic as __getitem__(), with a hook for returning a default value if the key doesn’t exist.
django.ref.request-response#django.http.QueryDict.get
QueryDict.getlist(key, default=None) Returns a list of the data with the requested key. Returns an empty list if the key doesn’t exist and default is None. It’s guaranteed to return a list unless the default value provided isn’t a list.
django.ref.request-response#django.http.QueryDict.getlist
QueryDict.items() Like dict.items(), except this uses the same last-value logic as __getitem__() and returns an iterator object instead of a view object. For example: >>> q = QueryDict('a=1&a=2&a=3') >>> list(q.items()) [('a', '3')]
django.ref.request-response#django.http.QueryDict.items
QueryDict.lists() Like items(), except it includes all values, as a list, for each member of the dictionary. For example: >>> q = QueryDict('a=1&a=2&a=3') >>> q.lists() [('a', ['1', '2', '3'])]
django.ref.request-response#django.http.QueryDict.lists
QueryDict.pop(key) Returns a list of values for the given key and removes them from the dictionary. Raises KeyError if the key does not exist. For example: >>> q = QueryDict('a=1&a=2&a=3', mutable=True) >>> q.pop('a') ['1', '2', '3']
django.ref.request-response#django.http.QueryDict.pop
QueryDict.popitem() Removes an arbitrary member of the dictionary (since there’s no concept of ordering), and returns a two value tuple containing the key and a list of all values for the key. Raises KeyError when called on an empty dictionary. For example: >>> q = QueryDict('a=1&a=2&a=3', mutable=True) >>> q.popitem...
django.ref.request-response#django.http.QueryDict.popitem
QueryDict.setdefault(key, default=None) Like dict.setdefault(), except it uses __setitem__() internally.
django.ref.request-response#django.http.QueryDict.setdefault
QueryDict.setlist(key, list_) Sets the given key to list_ (unlike __setitem__()).
django.ref.request-response#django.http.QueryDict.setlist
QueryDict.setlistdefault(key, default_list=None) Like setdefault(), except it takes a list of values instead of a single value.
django.ref.request-response#django.http.QueryDict.setlistdefault
QueryDict.update(other_dict) Takes either a QueryDict or a dictionary. Like dict.update(), except it appends to the current dictionary items rather than replacing them. For example: >>> q = QueryDict('a=1', mutable=True) >>> q.update({'a': '2'}) >>> q.getlist('a') ['1', '2'] >>> q['a'] # returns the last '2'
django.ref.request-response#django.http.QueryDict.update
QueryDict.urlencode(safe=None) Returns a string of the data in query string format. For example: >>> q = QueryDict('a=2&b=3&b=5') >>> q.urlencode() 'a=2&b=3&b=5' Use the safe parameter to pass characters which don’t require encoding. For example: >>> q = QueryDict(mutable=True) >>> q['next'] = '/a&b/' >>> q.urlencod...
django.ref.request-response#django.http.QueryDict.urlencode
QueryDict.values() Like dict.values(), except this uses the same last-value logic as __getitem__() and returns an iterator instead of a view object. For example: >>> q = QueryDict('a=1&a=2&a=3') >>> list(q.values()) ['3']
django.ref.request-response#django.http.QueryDict.values
class StreamingHttpResponse
django.ref.request-response#django.http.StreamingHttpResponse
StreamingHttpResponse.reason_phrase The HTTP reason phrase for the response. It uses the HTTP standard’s default reason phrases. Unless explicitly set, reason_phrase is determined by the value of status_code.
django.ref.request-response#django.http.StreamingHttpResponse.reason_phrase
StreamingHttpResponse.status_code The HTTP status code for the response. Unless reason_phrase is explicitly set, modifying the value of status_code outside the constructor will also modify the value of reason_phrase.
django.ref.request-response#django.http.StreamingHttpResponse.status_code
StreamingHttpResponse.streaming This is always True.
django.ref.request-response#django.http.StreamingHttpResponse.streaming
StreamingHttpResponse.streaming_content An iterator of the response content, bytestring encoded according to HttpResponse.charset.
django.ref.request-response#django.http.StreamingHttpResponse.streaming_content
Logging See also How to configure and use logging Django logging overview Django’s logging module extends Python’s builtin logging. Logging is configured as part of the general Django django.setup() function, so it’s always available unless explicitly disabled. Django’s default logging configuration By default, Dja...
django.ref.logging
Logging See also How to configure and use logging Django logging reference Python programmers will often use print() in their code as a quick and convenient debugging tool. Using the logging framework is only a little more effort than that, but it’s much more elegant and flexible. As well as being useful for debugg...
django.topics.logging
Managers class Manager A Manager is the interface through which database query operations are provided to Django models. At least one Manager exists for every model in a Django application. The way Manager classes work is documented in Making queries; this document specifically touches on model options that customi...
django.topics.db.managers
add_message(request, level, message, extra_tags='', fail_silently=False)
django.ref.contrib.messages#django.contrib.messages.add_message
get_messages(request)
django.ref.contrib.messages#django.contrib.messages.get_messages
class MessageMiddleware
django.ref.middleware#django.contrib.messages.middleware.MessageMiddleware
class storage.base.BaseStorage
django.ref.contrib.messages#django.contrib.messages.storage.base.BaseStorage
class storage.base.Message When you loop over the list of messages in a template, what you get are instances of the Message class. They have only a few attributes: message: The actual text of the message. level: An integer describing the type of the message (see the message levels section above). tags: A string c...
django.ref.contrib.messages#django.contrib.messages.storage.base.Message
class storage.cookie.CookieStorage This class stores the message data in a cookie (signed with a secret hash to prevent manipulation) to persist notifications across requests. Old messages are dropped if the cookie data size would exceed 2048 bytes. Changed in Django 3.2: Messages format was changed to the RFC 6265 ...
django.ref.contrib.messages#django.contrib.messages.storage.cookie.CookieStorage
class storage.fallback.FallbackStorage This class first uses CookieStorage, and falls back to using SessionStorage for the messages that could not fit in a single cookie. It also requires Django’s contrib.sessions application. This behavior avoids writing to the session whenever possible. It should provide the best p...
django.ref.contrib.messages#django.contrib.messages.storage.fallback.FallbackStorage
class storage.session.SessionStorage This class stores all messages inside of the request’s session. Therefore it requires Django’s contrib.sessions application.
django.ref.contrib.messages#django.contrib.messages.storage.session.SessionStorage
class views.SuccessMessageMixin Adds a success message attribute to FormView based classes get_success_message(cleaned_data) cleaned_data is the cleaned data from the form which is used for string formatting
django.ref.contrib.messages#django.contrib.messages.views.SuccessMessageMixin
get_success_message(cleaned_data) cleaned_data is the cleaned data from the form which is used for string formatting
django.ref.contrib.messages#django.contrib.messages.views.SuccessMessageMixin.get_success_message
Middleware This document explains all middleware components that come with Django. For information on how to use them and how to write your own middleware, see the middleware usage guide. Available middleware Cache middleware class UpdateCacheMiddleware class FetchFromCacheMiddleware Enable the site-wide cache....
django.ref.middleware
Middleware Middleware is a framework of hooks into Django’s request/response processing. It’s a light, low-level “plugin” system for globally altering Django’s input or output. Each middleware component is responsible for doing some specific function. For example, Django includes a middleware component, AuthenticationM...
django.topics.http.middleware
class FetchFromCacheMiddleware
django.ref.middleware#django.middleware.cache.FetchFromCacheMiddleware
class UpdateCacheMiddleware
django.ref.middleware#django.middleware.cache.UpdateCacheMiddleware
class XFrameOptionsMiddleware
django.ref.middleware#django.middleware.clickjacking.XFrameOptionsMiddleware
class BrokenLinkEmailsMiddleware
django.ref.middleware#django.middleware.common.BrokenLinkEmailsMiddleware
class CommonMiddleware
django.ref.middleware#django.middleware.common.CommonMiddleware
CommonMiddleware.response_redirect_class
django.ref.middleware#django.middleware.common.CommonMiddleware.response_redirect_class
class CsrfViewMiddleware
django.ref.middleware#django.middleware.csrf.CsrfViewMiddleware
class GZipMiddleware
django.ref.middleware#django.middleware.gzip.GZipMiddleware
class ConditionalGetMiddleware
django.ref.middleware#django.middleware.http.ConditionalGetMiddleware
class LocaleMiddleware
django.ref.middleware#django.middleware.locale.LocaleMiddleware
LocaleMiddleware.response_redirect_class
django.ref.middleware#django.middleware.locale.LocaleMiddleware.response_redirect_class
class SecurityMiddleware
django.ref.middleware#django.middleware.security.SecurityMiddleware
Migrations Migrations are Django’s way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema. They’re designed to be mostly automatic, but you’ll need to know when to make migrations, when to run them, and the common problems you might run into. The Commands T...
django.topics.migrations
Models Model API reference. For introductory material, see Models. Model field reference Field attribute reference Model index reference Constraints reference Model _meta API Related objects reference Model class reference Model Meta options Model instance reference QuerySet API reference Lookup API reference Query Ex...
django.ref.models.index
Models A model is the single, definitive source of information about your data. It contains the essential fields and behaviors of the data you’re storing. Generally, each model maps to a single database table. The basics: Each model is a Python class that subclasses django.db.models.Model. Each attribute of the model ...
django.topics.db.models
Pagination Django provides high-level and low-level ways to help you manage paginated data – that is, data that’s split across several pages, with “Previous/Next” links. The Paginator class Under the hood, all methods of pagination use the Paginator class. It does all the heavy lifting of actually splitting a QuerySet ...
django.topics.pagination
Paginator Django provides a few classes that help you manage paginated data – that is, data that’s split across several pages, with “Previous/Next” links. These classes live in django/core/paginator.py. For examples, see the Pagination topic guide. Paginator class class Paginator(object_list, per_page, orphans=0, al...
django.ref.paginator
class ArrayAgg(expression, distinct=False, filter=None, default=None, ordering=(), **extra) Returns a list of values, including nulls, concatenated into an array, or default if there are no values. distinct An optional boolean argument that determines if array values will be distinct. Defaults to False. order...
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.ArrayAgg
distinct An optional boolean argument that determines if array values will be distinct. Defaults to False.
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.ArrayAgg.distinct
ordering An optional string of a field name (with an optional "-" prefix which indicates descending order) or an expression (or a tuple or list of strings and/or expressions) that specifies the ordering of the elements in the result list. Examples: 'some_field' '-some_field' from django.db.models import F F('some_fie...
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.ArrayAgg.ordering
class BitAnd(expression, filter=None, default=None, **extra) Returns an int of the bitwise AND of all non-null input values, or default if all values are null.
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.BitAnd
class BitOr(expression, filter=None, default=None, **extra) Returns an int of the bitwise OR of all non-null input values, or default if all values are null.
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.BitOr
class BoolAnd(expression, filter=None, default=None, **extra) Returns True, if all input values are true, default if all values are null or if there are no values, otherwise False. Usage example: class Comment(models.Model): body = models.TextField() published = models.BooleanField() rank = models.Integer...
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.BoolAnd
class BoolOr(expression, filter=None, default=None, **extra) Returns True if at least one input value is true, default if all values are null or if there are no values, otherwise False. Usage example: class Comment(models.Model): body = models.TextField() published = models.BooleanField() rank = models.In...
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.BoolOr
class Corr(y, x, filter=None, default=None) Returns the correlation coefficient as a float, or default if there aren’t any matching rows.
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.Corr
class CovarPop(y, x, sample=False, filter=None, default=None) Returns the population covariance as a float, or default if there aren’t any matching rows. Has one optional argument: sample By default CovarPop returns the general population covariance. However, if sample=True, the return value will be the sample po...
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.CovarPop
sample By default CovarPop returns the general population covariance. However, if sample=True, the return value will be the sample population covariance.
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.CovarPop.sample
class JSONBAgg(expressions, distinct=False, filter=None, default=None, ordering=(), **extra) Returns the input values as a JSON array, or default if there are no values. You can query the result using key and index lookups. distinct New in Django 3.2. An optional boolean argument that determines if array values...
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.JSONBAgg
distinct New in Django 3.2. An optional boolean argument that determines if array values will be distinct. Defaults to False.
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.JSONBAgg.distinct
ordering New in Django 3.2. An optional string of a field name (with an optional "-" prefix which indicates descending order) or an expression (or a tuple or list of strings and/or expressions) that specifies the ordering of the elements in the result list. Examples are the same as for ArrayAgg.ordering.
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.JSONBAgg.ordering
class RegrAvgX(y, x, filter=None, default=None) Returns the average of the independent variable (sum(x)/N) as a float, or default if there aren’t any matching rows.
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.RegrAvgX
class RegrAvgY(y, x, filter=None, default=None) Returns the average of the dependent variable (sum(y)/N) as a float, or default if there aren’t any matching rows.
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.RegrAvgY
class RegrCount(y, x, filter=None) Returns an int of the number of input rows in which both expressions are not null. Note The default argument is not supported.
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.RegrCount
class RegrIntercept(y, x, filter=None, default=None) Returns the y-intercept of the least-squares-fit linear equation determined by the (x, y) pairs as a float, or default if there aren’t any matching rows.
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.RegrIntercept
class RegrR2(y, x, filter=None, default=None) Returns the square of the correlation coefficient as a float, or default if there aren’t any matching rows.
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.RegrR2
class RegrSlope(y, x, filter=None, default=None) Returns the slope of the least-squares-fit linear equation determined by the (x, y) pairs as a float, or default if there aren’t any matching rows.
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.RegrSlope
class RegrSXX(y, x, filter=None, default=None) Returns sum(x^2) - sum(x)^2/N (“sum of squares” of the independent variable) as a float, or default if there aren’t any matching rows.
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.RegrSXX
class RegrSXY(y, x, filter=None, default=None) Returns sum(x*y) - sum(x) * sum(y)/N (“sum of products” of independent times dependent variable) as a float, or default if there aren’t any matching rows.
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.RegrSXY
class RegrSYY(y, x, filter=None, default=None) Returns sum(y^2) - sum(y)^2/N (“sum of squares” of the dependent variable) as a float, or default if there aren’t any matching rows.
django.ref.contrib.postgres.aggregates#django.contrib.postgres.aggregates.RegrSYY