Multiple databases

This topic guide describes Django’s support for interacting with multiple databases. Most of the rest of Django’s documentation assumes you are interacting with a single database. If you want to interact with multiple databases, you’ll need to take some additional steps. Defining your databases The first step to using more than one database with Django is to tell Django about the database servers you’ll be using. This is done using the DATABASES setting. This setting maps database aliases, whic

Models and databases

A model is the single, definitive source of data 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. Models Making queries Aggregation Search Managers Performing raw SQL queries Database transactions Multiple databases Tablespaces Database access optimization Examples of model relationship API usage

Models

Model API reference. For introductory material, see Models. Model field reference Field attribute reference Model _meta API Related objects reference Model class reference Model Meta options Model instance reference QuerySet API reference Lookup API reference Query Expressions Conditional Expressions Database Functions

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 represents a database field. With all of this, Django gives you an automatically-generated database-access API; see Making queries. Quick example This example model defines a Person, wh

middleware.security.SecurityMiddleware

class SecurityMiddleware [source] The django.middleware.security.SecurityMiddleware provides several security enhancements to the request/response cycle. Each one can be independently enabled or disabled with a setting. SECURE_BROWSER_XSS_FILTER SECURE_CONTENT_TYPE_NOSNIFF SECURE_HSTS_INCLUDE_SUBDOMAINS SECURE_HSTS_SECONDS SECURE_REDIRECT_EXEMPT SECURE_SSL_HOST SECURE_SSL_REDIRECT

middleware.locale.LocaleMiddleware.response_redirect_class

LocaleMiddleware.response_redirect_class Defaults to HttpResponseRedirect. Subclass LocaleMiddleware and override the attribute to customize the redirects issued by the middleware.

middleware.locale.LocaleMiddleware

class LocaleMiddleware [source] Enables language selection based on data from the request. It customizes content for each user. See the internationalization documentation.

middleware.http.ConditionalGetMiddleware

class ConditionalGetMiddleware [source] Handles conditional GET operations. If the response has a ETag or Last-Modified header, and the request has If-None-Match or If-Modified-Since, the response is replaced by an HttpResponseNotModified. Also sets the Date and Content-Length response-headers.

middleware.gzip.GZipMiddleware

class GZipMiddleware [source] Warning Security researchers recently revealed that when compression techniques (including GZipMiddleware) are used on a website, the site may become exposed to a number of possible attacks. Before using GZipMiddleware on your site, you should consider very carefully whether you are subject to these attacks. If you’re in any doubt about whether you’re affected, you should avoid using GZipMiddleware. For more details, see the the BREACH paper (PDF) and breachatt

middleware.exception.ExceptionMiddleware

class ExceptionMiddleware New in Django 1.10. Catches exceptions raised during the request/response cycle and returns the appropriate response. Http404 is processed by handler404 (or a more friendly debug page if DEBUG=True). PermissionDenied is processed by handler403. MultiPartParserError is processed by handler400. SuspiciousOperation is processed by handler400 (or a more friendly debug page if DEBUG=True). Any other exception is processed by handler500 (or a more friendly debug pag