侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

3、Django命令行工具

2023-10-02 星期一 / 0 评论 / 0 点赞 / 49 阅读 / 4632 字

###一、命令行工具###django-admin.py是Django的一个用于管理任务的命令行工具,manage.py是对django-admin.py的简单包装,每个Django Project里

###一、命令行工具###

django-admin.py是Django的一个用于管理任务的命令行工具,manage.py是对django-admin.py的简单包装,每个Django Project里面都会包含一个manage.py

语法:

root># django-admin.py <subcommand> [options]root># manage.py <subcommand> [options]subcommand是字命令; options是可选的

###二、常用子命令###

1、新建一个django项目django-admin.py startproject project-name2、新建一个apppython manage.py startapp app-name3、运行开发服务器python manage.py runserver 0.0.0.0:8000或python manage.py runserver 0:80004、同步数据库python manage.py makemigrations   --生成数据库同步脚本python manage.py migrate  --同步数据库注意:Django 老版本可以使用用syncdbpython manage.py syncdb5、清空数据库python manage.py flush此命令会询问是 yes 还是 no, 选择 yes 会把数据全部清空掉,只留下空表。6、创建超级管理员python manage.py createsuperuser7、导出数据、导入数据python manage.py dumpdata appname > appname.jsonpython manage.py loaddata appname.json8、django项目环境终端python manage.py shell如果你安装了bpython或者ipython,会自动调用他们的界面9、数据库执行命令python manage.py dbshelldjango会进行到settings中设置的数据库,如果是mysql或者postgresql,会要求输入用户名和密码在这个终端可以输入sql语句10、编译语言文件python manage.py compilemessages11、创建语言文件python manage.py makemessages

###三、manage.py特有的一些子命令

1、创建超级管理员python manage.py createsuperuser2、修改密码python manage.py changepassword3、清除sessionspython manage.py clearsessions

四、查看帮助

1、查看django-admin.py帮助文档root># django-admin.py help startprojectusage: django-admin.py startproject [-h] [--version] [-v {0,1,2,3}]                                    [--settings SETTINGS]                                    [--pythonpath PYTHONPATH] [--traceback]                                    [--no-color] [--template TEMPLATE]                                    [--extension EXTENSIONS] [--name FILES]                                    name [directory]Creates a Django project directory structure for the given project name in thecurrent directory or optionally in the given directory.positional arguments:  name                  Name of the application or project.  directory             Optional destination directoryoptional 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.  --template TEMPLATE   The path or URL to load the template from.  --extension EXTENSIONS, -e EXTENSIONS                        The file extension(s) to render (default: "py").                        Separate multiple extensions with commas, or use -e                        multiple times.  --name FILES, -n FILES                        The file name(s) to render. Separate multiple                        extensions with commas, or use -n multiple times.2、查看manage.py帮助root># python manage.py helpType 'manage.py help <subcommand>' for help on a specific subcommand.Available subcommands:[auth]    changepassword    createsuperuser[contenttypes]    remove_stale_contenttypes[django]    check    compilemessages    createcachetable    dbshell    diffsettings    dumpdata    flush    inspectdb    loaddata    makemessages    makemigrations    migrate    sendtestemail    shell    showmigrations    sqlflush    sqlmigrate    sqlsequencereset    squashmigrations    startapp    startproject    test    testserver[sessions]    clearsessions[staticfiles]    collectstatic    findstatic    runserver

广告 广告

评论区