[Django]-Unable to start a django server in my computer

3👍

Your $DJANGO_SETTINGS_MODULE should just be set to ch3.settings. Just make sure that the ch3 app is in your $PYTHONPATH, too.

For example, if your app is at /Users/masi/Documents/Test/djangobook/, then set $DJANGO_SETTINGS_MODULE to ch3.settings, and make sure your $PYTHONPATH includes /Users/masi/Documents/Test/djangobook.

$ export PYTHONPATH=/Users/masi/Documents/Test/djangobook/
$ export DJANGO_SETTINGS_MODULE=ch3.settings
👤mipadi

1👍

From the django docs on django-admin.py and manage.py:

django-admin.py is Django’s command-line utility for administrative tasks.

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

  • 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.

Generally, when working on a single Django project, it’s easier to use manage.py

So, if your directory structure looks like:

djangobook/
    ch3/
        settings.py

Do the following and you can ignore all DJANGO environment variables (unless you have some really weird install):

$ cd /Users/masi/Documents/Test/djangobook/ch3/
$ python manage.py runserver

1👍

For those that come across the same error, when trying to run something similar:

python manage.py runserver --settings=settings_dev

When the settings file is within an app directory, like so:

mysite/
  settings.py
  settings_dev.py
requirements.txt
manage.py

You don’t have to specify $PYTHONPATH (at least not four years on) you just need to make sure your --settings value contains the folder name — you also need to use dot notation, slashes will not do.

python manage.py runserver --settings=mysite.settings_dev

It is the same story when exporting a $DJANGO_SETTINGS_MODULE value:

export DJANGO_SETTINGS_MODULE=mysite.settings_dev

Might save someone else the time that I lost working that out.

👤Pebbl

0👍

You can also try manage.py.

From your project directory, run

$ python manage.py runserver

Even though it’s just a wrapper, manage.py always works for me while django-admin.py doesn’t. Obviously we’re both doing something wrong (I just got started with Django), but this should get you going at least.

Leave a comment