Skip to content
Advertisement

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 manage.py 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:

DJANGO_SETTINGS_MODULE=

So I tried to set it manually:

$ export DJANGO_SETTINGS_MODULE='djangoapp.settings'

Running $ python manage.py 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.

Advertisement

Answer

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

Deleting the DJANGO_SETTINGS_MODULE environment variable should allow you to run both ./manage.py * 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 manage.py 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 ./manage.py rather than django-admin to run the management commands.

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