加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – django项目的初始设置问题

发布时间:2020-12-20 12:40:59 所属栏目:Python 来源:网络整理
导读:我正在从官方文档中学习Django,在 https://docs.djangoproject.com/en/1.7/intro/tutorial01/学习本教程时,我坚持创建一个项目部分. 当我运行django-admin.py startproject mysite时,我收到以下错误 C:Python34django-admin.py startproject mysiteUsage: d
我正在从官方文档中学习Django,在 https://docs.djangoproject.com/en/1.7/intro/tutorial01/学习本教程时,我坚持创建一个项目部分.

当我运行django-admin.py startproject mysite时,我收到以下错误

C:Python34>django-admin.py startproject mysite
Usage: django-admin.py subcommand [options] [args]
Options:
  -v VERBOSITY,--verbosity=VERBOSITY
                        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 exception
  --no-color            Don't colorize the command output.
  --version             show program's version number and exit
  -h,--help            show this help message and exit
Type 'django-admin.py help <subcommand>' for help on a specific subcommand.
Available subcommands:
[django]
    check
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    makemigrations
    migrate
    runfcgi
    runserver
    shell
    sql
    sqlall
    sqlclear
    sqlcustom
    sqldropindexes
    sqlflush
    sqlindexes
    sqlinitialdata
    sqlmigrate
    sqlsequencereset
    squashmigrations
    startapp
    startproject
    syncdb
    test
    testserver
    validate

请注意,由于未正确配置设置,因此仅列出Django核心命令

error: Requested setting INSTALLED_APPS,but settings are not configured
    . You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.).

我使用的是Python 3.4.1和django 1.7.我没有安装任何其他Django版本,这是我正在创建的第一个项目.

解决方法

确保您遵循 troubleshooting guide,因为您的系统路径上看起来没有正确的django-admin.py.来自文档:

django-admin.py should be on your system path if you installed Django
via python setup.py. If it’s not on your path,you can find it in
site-packages/django/bin,where site-packages is a directory within
your Python installation. Consider symlinking to django-admin.py from
some place on your path,such as /usr/local/bin.

您还应该为每个项目使用virtualenv,以允许隔离每个项目的依赖项并更轻松地管理它们. virtualenvwrapper是一个用于创建和管理virtualenvs的有用工具.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读