Skip to Content

Development Commands

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

Development Server

runserver_ngrok

Run development server with ngrok tunnel for webhook testing.

python manage.py runserver_ngrok [OPTIONS]
OptionTypeDescription
--domainTEXTCustom ngrok domain
--no-ngrokflagDisable ngrok for this session
[address:port]strCustom address and port

Examples:

# Start server with ngrok tunnel python manage.py runserver_ngrok # Use custom ngrok domain python manage.py runserver_ngrok --domain myapp # Custom port python manage.py runserver_ngrok 0.0.0.0:8080 # Disable ngrok for this session python manage.py runserver_ngrok --no-ngrok

Features:

  • ✅ Automatic ngrok tunnel creation
  • ✅ Public URL for webhooks
  • ✅ ALLOWED_HOSTS auto-configuration
  • ✅ Tunnel status monitoring

Output:

✅ Ngrok tunnel ready: https://abc123.ngrok.io Django development server is running at http://127.0.0.1:8000/ Public URL: https://abc123.ngrok.io

Testing Commands

test_email

Test email configuration and send test messages.

python manage.py test_email [OPTIONS]
OptionTypeDefaultDescription
--toTEXT-Recipient email address
--subjectTEXT"Django-CFG Test Email"Email subject
--backendTEXT-Email backend to test

Examples:

# Test email to specific address python manage.py test_email --to [email protected] # Custom subject python manage.py test_email --to [email protected] --subject "Configuration Test" # Test specific backend python manage.py test_email --to [email protected] --backend smtp

test_telegram

Test Telegram bot configuration.

python manage.py test_telegram [OPTIONS]
OptionTypeDescription
--messageTEXTTest message to send
--chat-idTEXTTarget chat ID (optional)

Examples:

# Send test message python manage.py test_telegram --message "Hello from Django-CFG!" # Send to specific chat python manage.py test_telegram --message "Test" --chat-id "-1001234567890"

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 SCRIPT_PATH [SCRIPT_ARGS]
ArgumentTypeDescription
SCRIPT_PATHPATHPath to Python script
SCRIPT_ARGS...Arguments to pass to script

Examples:

# Run Python script with Django context python manage.py script my_script.py # Pass arguments to script python manage.py script data_import.py --file data.csv # Run with specific settings python manage.py script --settings myproject.settings.dev cleanup.py

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 my_script.py admin

Project Structure

tree

Display Django project structure with documentation.

python manage.py tree [OPTIONS]
OptionTypeDescription
--depthINTEGERLimit depth
--include-docsflagInclude documentation files
--python-onlyflagShow only Python files

Examples:

# Show project structure python manage.py tree # Limit depth python manage.py tree --depth 3 # Include documentation files python manage.py tree --include-docs # Show only Python files python manage.py tree --python-only

Output:

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

Code Generation

generate

Generate Django components (models, views, serializers).

python manage.py generate TYPE NAME [FIELDS]
TypeDescription
modelGenerate model
crudGenerate complete CRUD
apiGenerate API views

Examples:

# Generate model python manage.py generate model Product name:str price:decimal # Generate complete CRUD python manage.py generate crud Product # Generate API views python manage.py generate api Product --viewset

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 with ngrok python manage.py runserver_ngrok

Webhook Development Workflow

# 1. Start server with ngrok python manage.py runserver_ngrok # Output: Public URL: https://abc123.ngrok.io # 2. Configure webhook in external service # Use: https://abc123.ngrok.io/api/webhooks/stripe/ # 3. Monitor webhook events # Check Django admin: /admin/payments/webhook/ # 4. Test webhook curl -X POST https://abc123.ngrok.io/api/webhooks/stripe/ \ -H "Content-Type: application/json" \ -d '{"event": "test"}'

Testing Workflow

# 1. Test email configuration python manage.py test_email --to [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 runserver_ngrok for webhook development
  • Use script command for reusable data operations (not one-off shell commands)
  • Use generate command for consistent code patterns

Troubleshooting

ProblemSolution
Ngrok not startingCheck: which ngrok, show_config --section ngrok
Email test failingCheck: check_settings --email-test, show_config --section email
Script errorsRun: script my_script.py --verbosity 2

See Also

Last updated on