简体   繁体   中英

How to use startproject (django-admin.py) if there is already a django project?

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)

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:

python django-admin.py startproject blog

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM