如果已经有 django 项目,如何使用 startproject (django-admin.py)?
我正在尝试启动一个新的 django 项目(使用 django-admin.py ),但不幸的是我总是收到以下错误:
C:\Users\NAME\dev\django>django-admin.py startproject foo
Usage: django-admin.py subcommand [options] [args]
[...]
这同样适用于 django-admin 的任何其他命令。 py - 每个命令都不存在。
我已经有一个 django 项目(在 C:\Users\NAME\dev\django\blog
中),并且我知道如果设置了 DJANGO_SETTINGS_MODULE
,startproject 命令将被禁用,但是当我尝试这个时:
>>> import os
>>> os.environ['DJANGO_SETTINGS_MODULE']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26\lib\os.py", line 423, in __getitem__
return self.data[key.upper()]
KeyError: 'DJANGO_SETTINGS_MODULE'
或者更好的是:
>>> from django.conf import settings
>>> dir(settings)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26\lib\site-packages\django\utils\functional.py", line 306, in __dir__
self._setup()
File "C:\Python26\lib\site-packages\django\conf\__init__.py", line 38, in _set up raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SE TTINGS_MODULE is undefined.
似乎 DJANGO_SETTINGS_MODULE
未定义。有人知道为什么我不能使用 django-admin.py 吗?
Django 1.2.3、Windows 7(64 位)
I am trying to start a new django project (using django-admin.py
) but unfortunately I'm always getting the following error:
C:\Users\NAME\dev\django>django-admin.py startproject foo
Usage: django-admin.py subcommand [options] [args]
[...]
The same applies to any other command of django-admin.py
- every command does not exist.
I already have a django projects (in C:\Users\NAME\dev\django\blog
) and I know that the startproject command is disabled if DJANGO_SETTINGS_MODULE
is set, but when I try this:
>>> import os
>>> os.environ['DJANGO_SETTINGS_MODULE']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26\lib\os.py", line 423, in __getitem__
return self.data[key.upper()]
KeyError: 'DJANGO_SETTINGS_MODULE'
Or even better this:
>>> from django.conf import settings
>>> dir(settings)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26\lib\site-packages\django\utils\functional.py", line 306, in __dir__
self._setup()
File "C:\Python26\lib\site-packages\django\conf\__init__.py", line 38, in _set up raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SE TTINGS_MODULE is undefined.
It seems that DJANGO_SETTINGS_MODULE
is undefined. Does anyone have an idea why I can't use django-admin.py
?
Django 1.2.3, Windows 7 (64bit)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅当您想要将 django-admin.py 与现有 Django 项目一起使用时,才需要 DJANGO_SETTINGS_MODULE 。
您的问题似乎有所不同,似乎 django-admin.py 由于某种原因不遵守命令行参数。从未在 Windows 上尝试过,但您是否尝试过执行以下操作:
现在我还看到您说您已经在该文件夹中拥有博客项目。那么为什么需要在同一个文件夹中启动同名的项目呢?请澄清您想要实现的目标。
DJANGO_SETTINGS_MODULE is only needed when you want to use django-admin.py with an existing Django project.
Your issue seems to be different, it seems like django-admin.py does not honor the command line parameters for some reason. Never tried it on Windows, but have you tried doing something like:
Now I also see you saying you already have blog project in that folder. Why do you need to start project with the same name in the same folder then? Please clarify what you are trying to achieve.