Python 2.7 has reached end of support
and will be
deprecated
on January 31, 2026. After deprecation, you won't be able to deploy Python 2.7
applications, even if your organization previously used an organization policy to
re-enable deployments of legacy runtimes. Your existing Python
2.7 applications will continue to run and receive traffic after their
deprecation date. We recommend that
you
migrate to the latest supported version of Python.
Stay organized with collections
Save and categorize content based on your preferences.
google.appengine.ext.ndb.django_middleware module
Summary
Django middleware for NDB.
Contents
- class google.appengine.ext.ndb.django_middleware.NdbDjangoMiddlewaresource
-
Bases: object
Django middleware for NDB.
To use NDB with django, add
‘ndb.NdbDjangoMiddleware’,
to the MIDDLEWARE_CLASSES entry in your Django settings.py file.
Or, if you are using the ndb version from the SDK, use
‘google.appengine.ext.ndb.NdbDjangoMiddleware’,
It’s best to insert it in front of any other middleware classes,
since some other middleware may make datastore calls and those won’t be
handled properly if that middleware is invoked before this middleware.
See http://docs.djangoproject.com/en/dev/topics/http/middleware/.
- process_exception(unused_request, unused_exception)source
-
Called by Django when a view raises an exception.
- process_request(unused_request)source
-
Called by Django before deciding which view to execute.
- process_response(request, response)source
-
Called by Django just before returning a response.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-06-16 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-16 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eNdbDjangoMiddleware\u003c/code\u003e class is Django middleware designed for use with NDB.\u003c/p\u003e\n"],["\u003cp\u003eTo integrate NDB with Django, add either \u003ccode\u003e'ndb.NdbDjangoMiddleware'\u003c/code\u003e or \u003ccode\u003e'google.appengine.ext.ndb.NdbDjangoMiddleware'\u003c/code\u003e to the \u003ccode\u003eMIDDLEWARE_CLASSES\u003c/code\u003e in your \u003ccode\u003esettings.py\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eIt is recommended to position this middleware ahead of other middleware classes to ensure proper handling of datastore calls.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eNdbDjangoMiddleware\u003c/code\u003e provides methods like \u003ccode\u003eprocess_request\u003c/code\u003e, \u003ccode\u003eprocess_response\u003c/code\u003e, and \u003ccode\u003eprocess_exception\u003c/code\u003e to interact with the Django request-response cycle.\u003c/p\u003e\n"]]],[],null,[]]