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]| Option | Type | Description |
|---|---|---|
--domain | TEXT | Custom ngrok domain |
--no-ngrok | flag | Disable ngrok for this session |
[address:port] | str | Custom 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-ngrokFeatures:
- ✅ 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.ioTesting Commands
test_email
Test email configuration and send test messages.
python manage.py test_email [OPTIONS]| Option | Type | Default | Description |
|---|---|---|---|
--to | TEXT | - | Recipient email address |
--subject | TEXT | "Django-CFG Test Email" | Email subject |
--backend | TEXT | - | 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 smtptest_telegram
Test Telegram bot configuration.
python manage.py test_telegram [OPTIONS]| Option | Type | Description |
|---|---|---|
--message | TEXT | Test message to send |
--chat-id | TEXT | Target 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]| Option | Type | Description |
|---|---|---|
--email | TEXT | Email 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]| Argument | Type | Description |
|---|---|---|
SCRIPT_PATH | PATH | Path 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.pyScript 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 adminProject Structure
tree
Display Django project structure with documentation.
python manage.py tree [OPTIONS]| Option | Type | Description |
|---|---|---|
--depth | INTEGER | Limit depth |
--include-docs | flag | Include documentation files |
--python-only | flag | Show 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-onlyOutput:
📁 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]| Type | Description |
|---|---|
model | Generate model |
crud | Generate complete CRUD |
api | Generate 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 --viewsetDevelopment 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_ngrokWebhook 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 testScript 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_ngrokfor webhook development - Use
scriptcommand for reusable data operations (not one-off shell commands) - Use
generatecommand for consistent code patterns
Troubleshooting
| Problem | Solution |
|---|---|
| Ngrok not starting | Check: which ngrok, show_config --section ngrok |
| Email test failing | Check: check_settings --email-test, show_config --section email |
| Script errors | Run: script my_script.py --verbosity 2 |
See Also
Last updated on