【发布时间】:2020-12-24 17:23:52
【问题描述】:
我正在从官方文档中学习 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 版本,这是我正在创建的第一个项目。
【问题讨论】:
-
您是否查看过故障排除指南docs.djangoproject.com/en/1.7/faq/troubleshooting/…?看起来你的系统路径上没有 django-admin.py
-
非常感谢。我浏览了故障排除指南,我所要做的就是 C:\Python34\Scripts>python django-admin.py startproject mysite 虽然我必须说我没有使用 virtualenv 来安装 django。但是预先添加 python 就可以了。
-
很酷,我会在答案中提供更多信息