django-extensions
$ pip install django-extensions
在Django项目的配置文件中,把 django_extensions 添加到 INSTALLED_APPS 列表中:
INSTALLED_APPS = (
...
'django_extensions',
)
再次运行 ./manage.py help 命令时,就可以看到新的命令.
[django_extensions]
admin_generator
clean_pyc
clear_cache
compile_pyc
create_app
create_command
create_jobs
create_template_tags
delete_squashed_migrations
describe_form
drop_test_database
dumpscript
export_emails
find_template
generate_secret_key
graph_models
mail_debug
notes
passwd
pipchecker
print_settings
print_user_for_session
reset_db #重置数据库 (目前支持 sqlite3, mysql, postgres),可以用来删除或创建数据库
runjob
runjobs
runprofileserver
runscript #在当前项目的环境下执行脚本
runserver_plus
set_default_site
set_fake_emails
set_fake_passwords
shell_plus # shell命令的扩展命令,运行Django shell的同时自动加载所有app的models,并选择使用Python shell的版本
show_template_tags
show_templatetags
show_urls
sqlcreate #根据配置文件的内容,生成创建数据库表的SQL语句
sqldiff
sqldsn
sync_s3
syncdata
unreferenced_files
update_permissions
validate_templates
runscript
--Runs a script in the django context.
$ python manage.py runscript --help
usage: manage.py runscript [-h] [--version] [-v {0,1,2,3}]
[--settings SETTINGS] [--pythonpath PYTHONPATH]
[--traceback] [--no-color] [--email-notifications]
[--email-exception] [--fixtures] [--noscripts] [-s]
[--no-traceback]
[--script-args [SCRIPT_ARGS [SCRIPT_ARGS ...]]]
script [script ...]
Runs a script in django context.
positional arguments:
script
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
-v {0,1,2,3}, --verbosity {0,1,2,3}
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on CommandError exceptions
--no-color Don't colorize the command output.
--email-notifications
Send email notifications for command.
--email-exception Send email for command exceptions.
--fixtures Only look in app.fixtures subdir
--noscripts Look in app.scripts subdir
-s, --silent Run silently, do not show errors and tracebacks
--no-traceback Do not show tracebacks
--script-args [SCRIPT_ARGS [SCRIPT_ARGS ...]]
Space-separated argument list to be passed to the
scripts. Note that the same arguments will be passed
to all named scripts.
python manage.py runscript delete_all_articles
Note: The command first checks for scripts in your apps i.e. app_name/scripts folder and runs them before checking for and running scripts in the project_root/scripts folder. You can have multiple scripts with the same name and they will all be run sequentially.
Passing arguments
Debugging
网友评论