Django Extensions is a comprehensive collection of custom extensions that enhance the Django web framework with additional management commands, utilities, and developer tools.
—
Django Extensions provides 44+ management commands that extend Django's built-in management system with powerful utilities for development, debugging, database operations, and administrative tasks. All commands are accessed via Django's manage.py: python manage.py <command_name>.
Commands that enhance the development workflow with improved shells, servers, and debugging tools.
# Enhanced shell with auto-imported models and utilities
def shell_plus():
"""
Like Django's 'shell' command but autoloads models of all installed Django apps.
Options:
--plain: Use plain Python interpreter instead of IPython/bpython
--ipython: Force IPython interpreter
--bpython: Force bpython interpreter
--notebook: Start Jupyter notebook with Django context
--kernel: Install Django kernel for Jupyter
--print-sql: Print SQL queries to stdout
"""
# Enhanced development server with debugging features
def runserver_plus():
"""
Starts enhanced development server with Werkzeug debugging capabilities.
Options:
--reloader-type: Type of reloader (auto, stat, watchdog)
--keep-meta-shutdown: Keep SHUTDOWN_MESSAGE meta variable
--nopin: Disable PIN-based authentication for debugger
"""
# Development server with profiling enabled
def runprofileserver():
"""
Starts lightweight web server with profiling enabled.
Options:
--prof-path: Directory to store profile files
--prof-file: Filename for profile output
--nomedia: Don't profile MEDIA_URL files
--use-lsprof: Use lsprof for profiling
"""
# Test mail server for development
def mail_debug():
"""
Starts a test mail server for development that prints emails to console.
Options:
--output: Output format (console, file)
--port: Port number (default: 1025)
"""Commands that generate boilerplate code and project structure.
# Generate admin.py file for models
def admin_generator():
"""
Generate admin.py file for the given app models.
Args:
app_name: Name of Django app
Options:
--print: Print to stdout instead of writing file
"""
# Create management command structure
def create_command():
"""
Creates Django management command directory structure.
Args:
app_name: Name of Django app
command_name: Name of management command
"""
# Create jobs directory structure
def create_jobs():
"""
Creates Django jobs command directory structure.
Args:
app_name: Name of Django app
"""
# Create template tags structure
def create_template_tags():
"""
Creates Django template tags directory structure.
Args:
app_name: Name of Django app
template_tag_name: Name of template tag library
"""Commands for database operations, analysis, and management.
# Reset database completely
def reset_db():
"""
Resets the database for this project.
Options:
--noinput: Don't prompt for confirmation
--router: Database router to use
--close-sessions: Close database sessions before reset
"""
# Generate SQL for database creation
def sqlcreate():
"""
Generates SQL to create database as specified in settings.py.
Options:
--router: Database router to use
"""
# Show differences between models and database
def sqldiff():
"""
Prints approximated difference between models and database fields.
Args:
app_names: Names of apps to analyze (optional)
Options:
--all-applications: Check all installed applications
--not-only-existing: Include non-existing tables
"""
# Export database as Python script
def dumpscript():
"""
Dumps data as customized Python script.
Args:
app_names: Names of apps to dump (optional)
Options:
--stdout: Output to stdout instead of file
--format: Output format (python, json, xml, yaml)
"""
# Show differences between models and database
def sqldiff():
"""
Prints approximated difference between models and database fields.
Args:
app_names: Names of apps to analyze (optional)
Options:
--all-applications: Check all installed applications
--not-only-existing: Include non-existing tables
"""
# Sync data to match fixtures exactly
def syncdata():
"""
Makes database have same data as fixtures, no more, no less.
Args:
fixture_names: Names of fixture files
Options:
--skip-remove: Don't remove objects not in fixtures
"""
# Drop test database
def drop_test_database():
"""
Drops test database for this project.
Options:
--noinput: Don't prompt for confirmation
"""
# Manage database state
def managestate():
"""
Manage database state in convenient way.
Options:
--list: List available states
--save: Save current state
--load: Load saved state
"""
# Merge duplicate model instances
def merge_model_instances():
"""
Removes duplicate model instances based on specified field.
Args:
model_name: Name of model to process
field_name: Field to check for duplicates
Options:
--noinput: Don't prompt for confirmation
"""Commands for analyzing and inspecting Django projects.
# Generate model relationship diagrams
def graph_models():
"""
Creates GraphViz dot file for specified app names.
Args:
app_names: Names of apps to include (optional)
Options:
--output: Output file path
--layout: Graph layout (dot, neato, fdp, sfdp, twopi, circo)
--theme: Graph theme (original, django2018)
--group-models: Group models by application
--all-applications: Include all installed applications
--include-models: Comma-separated list of models to include
--exclude-models: Comma-separated list of models to exclude
"""
# Display URL patterns
def show_urls():
"""
Displays all URL matching routes for the project.
Options:
--urlconf: Specify URLconf module
--format: Output format (dense, table, aligned, vertical)
--decorator: Show view decorators
--language: Show for specific language
"""
# List model information
def list_model_info():
"""
List fields and methods for each model.
Args:
app_names: Names of apps to analyze (optional)
"""
# Show template tags and filters
def show_template_tags():
"""
Displays template tags and filters available in current project.
Options:
--show-builtins: Include built-in template tags
"""
# Find template location
def find_template():
"""
Finds location of given template by resolving its path.
Args:
template_name: Name of template to find
"""
# List Django signals
def list_signals():
"""
List all signals by model and signal type.
Args:
app_names: Names of apps to analyze (optional)
"""
# Show code annotations (TODO, FIXME, etc.)
def notes():
"""
Show annotations like TODO, FIXME, BUG, HACK, WARNING, NOTE, XXX.
Options:
--tag: Specific annotation tag to search for
"""
# Check pip requirements for updates
def pipchecker():
"""
Scan pip requirement files for out-of-date packages.
Options:
--requirements: Path to requirements file
--github-token: GitHub token for API access
"""
# Find unreferenced media files
def unreferenced_files():
"""
Prints list of files in MEDIA_ROOT not referenced in database.
Options:
--media-root: Override MEDIA_ROOT setting
"""
# Validate templates for syntax errors
def validate_templates():
"""
Validate templates for syntax and compile errors.
Args:
app_names: Names of apps to validate (optional)
"""
# Update model permissions
def update_permissions():
"""
Reloads permissions for specified apps or all apps.
Args:
app_names: Names of apps to update (optional)
"""
# Print database DSN
def sqldsn():
"""
Prints database DSN as specified in settings.py.
Options:
--router: Database router to use
"""Utility commands for common development tasks.
# Print Django settings
def print_settings():
"""
Print active Django settings.
Options:
--format: Output format (text, json, yaml)
--indent: Indentation for formatted output
"""
# Generate random password
def generate_password():
"""
Generates new password using Django's default password generator.
Options:
--length: Password length (default: 10)
"""
# Generate secret key
def generate_secret_key():
"""
Generates new SECRET_KEY for Django settings.
Options:
--length: Key length (default: 50)
"""
# Clean Python bytecode files
def clean_pyc():
"""
Removes all Python bytecode compiled files from project.
Options:
--optimize: Also remove .pyo files
--path: Specific path to clean
"""
# Compile Python bytecode files
def compile_pyc():
"""
Compile Python bytecode files for the project.
Options:
--path: Specific path to compile
"""
# Clear Django cache
def clear_cache():
"""
Fully clear site-wide cache.
Options:
--cache: Specific cache to clear
"""
# Run maintenance jobs
def runjobs():
"""
Runs scheduled maintenance jobs.
Args:
frequency: Job frequency (hourly, daily, weekly, monthly, yearly)
Options:
--list: List available jobs
"""
# Run single maintenance job
def runjob():
"""
Run single maintenance job.
Args:
job_name: Name of job to run
"""
# Run Python script in Django context
def runscript():
"""
Runs Python script in Django context.
Args:
script_name: Name of script to run
Options:
--script-args: Arguments to pass to script
"""
# Set default site parameters
def set_default_site():
"""
Set parameters of default django.contrib.sites Site.
Options:
--system-fqdn: Use system FQDN
--name: Site name
--domain: Site domain
"""
# Export user emails
def export_emails():
"""
Export user email addresses in various formats.
Options:
--format: Output format (address, name_email, json)
--output: Output file path
"""
# Print user for session
def print_user_for_session():
"""
Print user information for provided session key.
Args:
session_key: Django session key
"""
# Validate templates
def validate_templates():
"""
Validate templates for syntax and compile errors.
Args:
app_names: Names of apps to validate (optional)
"""
# Update model permissions
def update_permissions():
"""
Reloads permissions for specified apps or all apps.
Args:
app_names: Names of apps to update (optional)
"""
# Raise test exception
def raise_test_exception():
"""
Raises test Exception named DjangoExtensionsTestException.
Used for testing error handling and logging.
"""
# Describe form from model
def describe_form():
"""
Outputs specified model as form definition to shell.
Args:
model_name: Name of model to describe
"""
# Set fake user emails (DEBUG only)
def set_fake_emails():
"""
DEBUG only: Give all users new email based on account data.
Args:
email_template: Email template (default: "%s@example.com")
"""
# Set fake user passwords (DEBUG only)
def set_fake_passwords():
"""
DEBUG only: Sets all user passwords to common value.
Args:
password: Password to set for all users
"""
# Sync media files to S3
def sync_s3():
"""
Syncs complete MEDIA_ROOT structure and files to S3 bucket.
Args:
bucket_name: Name of S3 bucket
Options:
--aws-access-key-id: AWS access key ID
--aws-secret-access-key: AWS secret access key
--prefix: S3 key prefix
"""
# Delete squashed migrations
def delete_squashed_migrations():
"""
Deletes migrations replaced by squashed migration.
Options:
--noinput: Don't prompt for confirmation
"""
# Reset database schema
def reset_schema():
"""
Recreates public schema for this project.
Options:
--noinput: Don't prompt for confirmation
"""
# Print database DSN
def sqldsn():
"""
Prints database DSN as specified in settings.py.
Options:
--router: Database router to use
"""# Enhanced shell with all models imported
python manage.py shell_plus
# Show all URL patterns in a table format
python manage.py show_urls --format=table
# Generate model diagram for specific apps
python manage.py graph_models myapp anotherapp --output=models.png
# Reset database (be careful!)
python manage.py reset_db --noinput
# Export data as Python script
python manage.py dumpscript myapp > data_export.py
# Check for code annotations
python manage.py notes
# Generate a new secret key
python manage.py generate_secret_key
# Run the enhanced development server
python manage.py runserver_plus
# Profile the development server
python manage.py runprofileserver --prof-path=/tmp/profiles/Install with Tessl CLI
npx tessl i tessl/pypi-django-extensions