开发者

how to initialize the built in django development server on OSX 10.7 (lion)

开发者 https://www.devze.com 2023-03-22 23:42 出处:网络
when running $ django-admin.py runserver I get: (in red letters) Error: 开发者_如何学PythonSettings cannot be imported, because environment variable

when running

$ django-admin.py runserver

I get: (in red letters)

Error: 开发者_如何学PythonSettings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

in previous versions (python 2.5, django 1.2) I never had this problem. Ive tried setting the setting module manually then it tells me to put it on sys.path. once I set the sys path in bash using the python interpreter I close it and it dissappears from the sys.path? Im using OSX 10.7's Apache 2.2.19 and python 2.7.1 build right out of the box. Running out of ideas. Help!!


Why do people keep trying to run the devserver with django-admin.py? Where is this documented?

The correct way to do it is with manage.py.


I actually figured it out. for anyone else that has become as forgetful as I, you have to pass those variable to the shell by adding python to the front of it.

python manage.py runserver

without the python in front of it the shell doesn't know where to send it.


You have to use django-admin.py to start the devserver if you have a more custom setup (i.e. a settings file that isn't called settings.py or you have multiple settings files and want to switch between them).

When you use django-admin.py you have to give it two extra command line arguments so that it knows where your project is and what settings file to use.

For example:

Your project exists in: /path/to/myproject

Settings file: /path/to/myproject/site1.py

django-admin.py runserver --pythonpath=/path/to/myproject --settings=site1
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号