Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
513 views
in Technique[技术] by (71.8m points)

"python manage.py runserver" vs "django-admin runserver"

I have an app, Scaffold, installed, that runs perfectly when I use python manage.py runserver but when I try to start it using django-admin, it fails;

You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

I try calling it with django-admin migrate --settings=scaffold.settings And I get; ImportError: No module named scaffold.settings

I've tried multiple things, googled around, but can't seem to figure out what I need to change. The settings.py file is in the directory ..scaffold but I am no longer certain that is the one I need to use.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should be using manage.py unless have a specific reason for not wanting project-specific configuration. According to the docs

manage.py is automatically created in each Django project. manage.py is a thin wrapper around django-admin that takes care of several things for you before delegating to django-admin:

  • It puts your project’s package on sys.path.
  • It sets the DJANGO_SETTINGS_MODULE environment variable so that it points to your project’s settings.py file.
  • It calls django.setup() to initialize various internals of Django.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...