Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
517 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 Answer

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...