django-extensions

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Django Extensions

Django Extensions

This project has django-extensions installed. Use these commands to understand and interact with the Django project.
本项目已安装django-extensions。可使用以下命令来了解并与Django项目进行交互。

Introspection

项目内省

Show URL Routes

查看URL路由

bash
python manage.py show_urls
bash
python manage.py show_urls

List Model Information

列出模型信息

bash
undefined
bash
undefined

All models

所有模型

python manage.py list_model_info
python manage.py list_model_info

Specific model with signatures and field classes

带签名和字段类的指定模型

python manage.py list_model_info --model <app.Model> --signature --field-class
python manage.py list_model_info --model <app.Model> --signature --field-class

All methods including private

包含私有方法在内的所有方法

python manage.py list_model_info --model <app.Model> --all-methods --signature
undefined
python manage.py list_model_info --model <app.Model> --all-methods --signature
undefined

Print Settings

打印配置信息

bash
undefined
bash
undefined

All settings

所有配置

python manage.py print_settings --format=pprint
python manage.py print_settings --format=pprint

Wildcards supported

支持通配符

python manage.py print_settings AUTH* python manage.py print_settings DATABASE* python manage.py print_settings *_DIRS
undefined
python manage.py print_settings AUTH* python manage.py print_settings DATABASE* python manage.py print_settings *_DIRS
undefined

Show Permissions

查看权限

bash
python manage.py show_permissions
python manage.py show_permissions <app_label>
bash
python manage.py show_permissions
python manage.py show_permissions <app_label>

Show Template Tags

查看模板标签

bash
python manage.py show_template_tags
bash
python manage.py show_template_tags

Development

开发调试

Enhanced Shell (shell_plus)

增强版Shell(shell_plus)

bash
python manage.py shell_plus
python manage.py shell_plus --print-sql
Auto-imports all models. Use
--dont-load app1
to skip apps.
bash
python manage.py shell_plus
python manage.py shell_plus --print-sql
自动导入所有模型。可使用
--dont-load app1
参数跳过指定应用。

Enhanced Dev Server (runserver_plus)

增强版开发服务器(runserver_plus)

bash
python manage.py runserver_plus
python manage.py runserver_plus --print-sql
Includes Werkzeug debugger for interactive debugging.
bash
python manage.py runserver_plus
python manage.py runserver_plus --print-sql
集成Werkzeug调试器,支持交互式调试。

Database

数据库操作

SQL Diff (Compare Models to Schema)

SQL差异对比(模型与架构对比)

bash
python manage.py sqldiff -a        # SQL differences
python manage.py sqldiff -a -t     # Text differences (readable)
bash
python manage.py sqldiff -a        # SQL语句差异
python manage.py sqldiff -a -t     # 可读文本格式差异

Script Execution

脚本执行

Run Scripts with Django Context

在Django上下文环境中运行脚本

bash
python manage.py runscript <script_name>
python manage.py runscript <script_name> --script-args arg1 arg2
python manage.py runscript <script_name> --traceback
Scripts in
scripts/
directory must define a
run()
function.
bash
python manage.py runscript <script_name>
python manage.py runscript <script_name> --script-args arg1 arg2
python manage.py runscript <script_name> --traceback
scripts/
目录下的脚本必须定义
run()
函数。

Profiling

性能分析

Profile Server Requests

分析服务器请求性能

bash
python manage.py runprofileserver --prof-path=/tmp/profiles
python manage.py runprofileserver --use-cprofile --prof-path=/tmp/profiles
python manage.py runprofileserver --kcachegrind --prof-path=/tmp/profiles
bash
python manage.py runprofileserver --prof-path=/tmp/profiles
python manage.py runprofileserver --use-cprofile --prof-path=/tmp/profiles
python manage.py runprofileserver --kcachegrind --prof-path=/tmp/profiles

Notes

注意事项

  • Model notation:
    app.ModelName
    (e.g.,
    core.EmailAccount
    ,
    metabox.Thread
    )
  • Settings wildcards:
    AUTH*
    ,
    *_DIRS
    ,
    DATABASE*
  • Commands run from project root
  • 模型表示方式:
    app.ModelName
    (例如:
    core.EmailAccount
    ,
    metabox.Thread
  • 配置通配符:
    AUTH*
    ,
    *_DIRS
    ,
    DATABASE*
  • 所有命令需在项目根目录下执行