Skip to Content

Development Commands

Commands for development, testing, and debugging Django-CFG projects.

Testing Commands

test_email

Send the built-in email templates to one address through the configured backend.

python manage.py test_email --email ADDRESS [--type TYPE]
OptionTypeDefaultDescription
--emailTEXTrequiredRecipient address. A user with this email is created if none exists
--typeTEXTallTemplate to send: all, base, otp, welcome, login_alert

Examples:

# All templates python manage.py test_email --email [email protected] # One template python manage.py test_email --email [email protected] --type otp

The command has no default recipient: running it without --email is an error.


test_telegram

Test Telegram bot configuration.

python manage.py test_telegram [OPTIONS]
OptionTypeDescription
--messageTEXTTest message to send

Examples:

# Send test message python manage.py test_telegram --message "Hello from Django-CFG!"

otp_test

Test OTP authentication system.

python manage.py otp_test [OPTIONS]
OptionTypeDescription
--emailTEXTEmail address to test

Examples:

# Test email OTP python manage.py otp_test --email [email protected]

Script Execution

script

Run custom scripts with full Django context.

python manage.py script [OPTIONS]
OptionTypeDescription
--scriptTEXTName of the script to run
--listflagList available scripts
--createTEXTCreate a new script template with this name
--shellflagOpen a Django shell
--checkflagRun the Django system check

Without options it opens an interactive menu.

Examples:

# Run a script with Django context python manage.py script --script my_script # List available scripts python manage.py script --list # Create a script template python manage.py script --create my_script

Script Example:

# my_script.py import sys from myapp.models import User def main(): print(f"Total users: {User.objects.count()}") if len(sys.argv) > 1: username = sys.argv[1] user = User.objects.get(username=username) print(f"Found user: {user.email}") if __name__ == "__main__": main()

Usage:

python manage.py script --script my_script

Project Structure

tree

Display Django project structure with documentation.

python manage.py tree [OPTIONS]
OptionTypeDescription
--depth, -LINTEGERLimit depth
--all, -aflagInclude hidden files
--dirs-only, -dflagDirectories only
--no-ignore, -nflagDo not skip node_modules, .git and similar
--include-dockerflagInclude Docker configuration and volumes
--include-logsflagInclude log files
--output, -oFILEWrite to a file instead of stdout
--formattree|json|xmlOutput format

Examples:

# Show project structure python manage.py tree # Limit depth python manage.py tree --depth 3 # Directories only python manage.py tree --dirs-only # Write to a file python manage.py tree --output tree.txt

Output:

📁 myproject/ ├── 📄 manage.py ├── 📁 myproject/ │ ├── 📄 __init__.py │ ├── 📄 config.py │ ├── 📄 settings.py │ ├── 📄 urls.py │ └── 📄 wsgi.py ├── 📁 apps/ │ ├── 📁 blog/ │ ├── 📁 shop/ │ └── 📁 profiles/ └── 📁 static/

Code Generation

Generating API clients and FastAPI models has its own commands: gen (Code Generation) and generate_fastapi.


Development Workflows

Complete Development Setup

# 1. Create project django-cfg create-project my_project cd my_project/projects/django # 2. Install dependencies poetry install # 3. Setup database poetry run python manage.py migrate # 4. Create superuser poetry run python manage.py createsuperuser # 5. Start development server python manage.py runserver

Webhook Development Workflow

Exposing your local server to the internet is outside Django-CFG’s scope — run a tunnel yourself (for example ngrok http 8000 or cloudflared tunnel) and point your webhook provider at the resulting public URL.

# 1. Start the development server python manage.py runserver # 2. Configure the webhook in the external service # Use: https://<your-public-url>/api/webhooks/stripe/ # 3. Monitor webhook events # Check Django admin: /admin/payments/webhook/ # 4. Test webhook curl -X POST https://<your-public-url>/api/webhooks/stripe/ \ -H "Content-Type: application/json" \ -d '{"event": "test"}'

Testing Workflow

# 1. Test email configuration python manage.py test_email --email [email protected] # 2. Test Telegram bot python manage.py test_telegram --message "Deploy test" # 3. Test OTP system python manage.py otp_test --email [email protected] # 4. Run unit tests python manage.py test

Script Development Workflow

# 1. Create script cat > scripts/import_users.py << EOF from myapp.models import User import csv def main(): with open('users.csv') as f: reader = csv.DictReader(f) for row in reader: User.objects.create( username=row['username'], email=row['email'] ) print("Import complete!") if __name__ == "__main__": main() EOF # 2. Run script python manage.py script scripts/import_users.py # 3. Check results python manage.py shell -c "from myapp.models import User; print(User.objects.count())"

Tips

  • Use script command for reusable data operations (not one-off shell commands)
  • Use generate command for consistent code patterns

Troubleshooting

ProblemSolution
Email test failingCheck: check_settings --email-test, show_config
Script errorsRun: script my_script.py --verbosity 2

See Also

Last updated on