Django Code Examples

Django is a Python web framework.

Official Django logo. Trademark Django Software Foundation.

Django Example Projects

Part of Django's widespread adoption comes from its broad ecosystem of open source code libraries and example projects.

It's good to familiarize yourself with the following projects to learn what is available to you beyond the extensive "batteries-included" code base.

These projects, ordered alphabetically, are also helpful as example code for how to build your own applications.

AuditLog

Auditlog (project documentation) is a Django app that logs changes to Python objects, similar to the Django admin's logs but with more details and output formats. Auditlog's source code is provided as open source under the MIT license.

Example code found in the AuditLog project:

dccnsys

dccnsys is a conference registration system built with Django. The code is open source under the MIT license.

dccnsys is shown on the following code example pages:

django-allauth

django-allauth (project website) is a Django library for easily adding local and social authentication flows to Django projects. It is open source under the MIT License.

Code used for examples from the django-allauth project:

django-angular

django-angular (project examples website) is a library with helper code to make it easier to use Angular as the front-end to Django projects. The code for django-angular is open source under the MIT license.

Code from django-angular is shown on:

django-axes

django-axes (project documentation and PyPI package information is a code library for Django projects to track failed login attempts against a web application. The goal of the project is to make it easier for you to stop people and scripts from hacking your Django-powered website.

The code for django-axes is open source under the MIT liense and maintained by the group of developers known as Jazzband.

django-cors-headers

django-cors-headers is an open source library for enabling Cross-Origin Resource Sharing (CORS) handling in your Django web applications and appropriately dealing with HTTP headers for CORS requests.

Code examples from the django-cors-headers project:

django-cms

django-cms (project website) is a Python-based content management system (CMS) library for use with Django web apps that is open sourced under the BSD 3-Clause "New" License.

Example code from django-cms:

django-debug-toolbar

django-debug-toolbar (project documentation and PyPI page) grants a developer detailed request-response cycle information while developing a Django web application. The code for django-debug-toolbar is open source and maintained by the developer community group known as Jazzband.

django-easy-timezones

django-easy-timezones (project website) is a Django middleware code library to simplify handling time data in your applications using users' geolocation data.

Useful example code found within django-easy-timezones:

django-extensions

django-extensions (project documentation and PyPI page) is a Django project that adds a bunch of additional useful commands to the manage.py interface. This GoDjango video provides a quick overview of what you get when you install it into your Python environment.

The django-extensions project is open sourced under the MIT license.

django-filer

django-filer (project documentation) is a file management library for uploading and organizing files and images in Django's admin interface. The project's code is available under the BSD 3-Clause "New" or "Revised" open source license.

Code from django-filer can be found on these pages:

django-floppyforms

django-floppyforms (project documentation and PyPI page) is a Django code library for better control over rendering HTML forms in your templates.

The django-floppyforms code is provided as open source and maintained by the collaborative developer community group Jazzband.

Code from django-floppyforms is used as examples for the following parts of Django:

django-haystack

django-haystack (project website and PyPI page) is a search abstraction layer that separates the Python search code in a Django web application from the search engine implementation that it runs on, such as Apache Solr, Elasticsearch or Whoosh.

The django-haystack project is open source under the BSD license.

django-jet

django-jet (project documentation, PyPI project page and more information) is a fancy Django Admin panel replacement.

The django-jet project is open source under the GNU Affero General Public License v3.0.

django-jsonfield

django-jsonfield (jsonfield on PyPi) is a Django code library that makes it easier to store validated JSON in a Django object-relational mapper (ORM) database model.

The django-jsonfield project is open source under the MIT license.

django-model-utils

django-model-utils (project documentation and PyPI package information) provides useful mixins and utilities for working with Django ORM models in your projects.

The django-model-utils project is open sourced under the BSD 3-Clause "New" or "Revised" License and it is maintained by the developer community group Jazzband.

django-mongonaut

django-mongonaut (project documentation and PyPI package information) provides an introspective interface for working with MongoDB via mongoengine. The project has its own new code to map MongoDB to the Django Admin interface.

django-mongonaut's highlighted features include:

* Automatic introspection of mongoengine documents
* The ability to constrain who sees what and what they can do
* Full control for adding, editing and deleting documents

The django-mongonaut project is open sourced under the MIT License and it is maintained by the developer community group Jazzband.

django-oauth-toolkit

django-oauth-toolkit (project website and PyPI package information) is a code library for adding and handling OAuth2 flows within your Django web application and API.

The django-oauth-toolkit project is open sourced under the FreeBSD license and it is maintained by the developer community group Jazzband.

Code examples provided by django-oauth-toolkit:

django-oscar

django-oscar (project website) is a framework for building e-commerce sites on top of Django. The code for the project is available open source under a custom license written by Tangent Communications PLC.

Further code examples from django-oscar:

django-pipeline

django-pipeline (project documentation and PyPI package information) is a code library for handling and compressing static content assets when handling requests in Django web applications.

The django-pipeline project is open sourced under the MIT License and it is maintained by the developer community group Jazzband.

django-push-notifications

django-push-notifications is a Django app for storing and interacting with push notification services such as Google's Firebase Cloud Messaging and Apple Notifications. The django-push-notification project's source code is available open source under the MIT license.

django-smithy

django-smithy is a Django code library that allows users to send HTTP requests from the Django admin user interface. The code for the project is open source under the MIT license.

Code examples from django-smithy are shown on the following pages:

django-taggit

django-taggit (project documentation) PyPI page) provides a way to create, store, manage and use tags in a Django project. The code for django-taggit is open source and maintained by the collaborative developer community group Jazzband.

drf-action-serializer

drf-action-serializer (PyPI page) is an extension for Django REST Framework that makes it easier to configure specific serializers to use based on the client's request action. For example, a list view should have one serializer whereas the detail view would have a different serializer.

The project is open source under the MIT license.

There are code examples from the drf-action-serializer project on the following pages:

gadget-board

gadget-board is a Django, Django REST Framework (DRF) and Angular web application that is open source under the Apache2 license.

Additional example code found within gadget-board:

jazzband

jazzband is a Django-based web application that runs a website with information on many Django projects such as django-debug-toolbar and django-taggit.

The project's code is provided as open source under the MIT license.

register

register is a Django, Bootstrap, PostgreSQL project that is open source under the GNU General Public License v3.0. This web application makes it easier for people to register as organ donors. You can see the application live at https://register.organize.org/.

Useful example code from register can be found on:

wagtail

wagtail (project website) is a fantastic Django-based CMS with code that is open source under the BSD 3-Clause "New" or "Revised" License.

Example code from wagtail shown on these pages:

1. Introduction 2. Development Environments 3. Data 4. Web Development 5. Deployment 6. DevOps Changelog What Full Stack Means About the Author Future Directions Page Statuses Django Code Examples django.urls.path django.conf.urls.url django.contrib.admin django.db.models Model django.dispatch Signal django.db.models.signal django.core.mail.send_mail django.core.mail.messages EmailMessage django.conf settings django.forms django.contrib.admin.sites register django.core.management.base BaseCommand django.utils.timezone django.contrib.auth get_user_model django.contrib.auth.decorators login_required django.core.exceptions ImproperlyConfigured django.utils.html format_html django.contrib.auth.hashers make_password django.http Http404 django.http HttpResponse django.http HttpResponseForbidden django.http HttpResponseBadRequest django.contrib.admin.filters SimpleListFilter django.urls.exceptions NoReverseMatch django.http HttpResponsePermanentRedirect django.http HttpResponseNotModified django.http HttpResponseRedirect django.apps.config AppConfig django.db OperationalError flask_sqlalchemy.SQLAlchemy Model django.db.models CharField django.db.models TextField django.db.models BooleanField flask request flask redirect django.db.models DateTimeField django.db.models IntegerField django.db.models AutoField django.db.models DateField django.db.models FileField django.template.response TemplateResponse django.template.response SimpleTemplateResponse SQLAlchemy Model Examples django.urls reverse_lazy Flask Core and Extensions Code Examples ...or view the full table of contents.

Full Stack Python

Full Stack Python is an open book that explains concepts in plain language and provides helpful resources for those topics.
Updates via Twitter & Facebook.

Matt Makai 2012-2019