Skip to content

Can’t seem to setup my Django project properly

I was trying the official tutorial of Django because I want to learn it. I run Archlinux 4.10.11-1 64 bits.

First, I created a folder named djangoapp where I set my virtual environment:

$ virtualenv djangoapp

I set my current directory to this folder, and then I activated it:

$ source bin/activate

And I installed Django after:

$ pip install django

Following the tutorial, I ran:

$ django-admin startproject djangoapp

And set my current directory to djangoapp, and ran:

$ python runserver

But I’m getting the following error:

django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

Indeed, running env | grep DJANGO_SETTINGS_MODULE gets me the following result:


So I tried to set it manually:

$ export DJANGO_SETTINGS_MODULE='djangoapp.settings'

Running $ python runserver now works, but $ django-admin help now gets me the following error:

ModuleNotFoundError: No module named ‘djangoapp’

What did I do wrong? Thanks for your help!

PS: $ python --version gets me Python 3.6.1.



I think the docs could be a little clearer about this, but django-admin is typically only used for running django-admin startproject and is used for the rest e.g. ./ runserver, ./ migrate etc.

Deleting the DJANGO_SETTINGS_MODULE environment variable should allow you to run both ./ * and django-admin startproject commands when inside the djangoapp folder.

I’m not sure how to do this on Archlinux, but something like unset DJANGO_SETTINGS_MODULE or set -e DJANGO_SETTINGS_MODULE should work.

Further info: you can think of as a wrapper around django-admin that automatically sets the PYTHONPATH and DJANGO_SETTINGS_MODULE environment variables. Therefore, once inside the project, you can just use ./ rather than django-admin to run the management commands.

User contributions licensed under: CC BY-SA
5 People found this is helpful