🎓 A1Learner
🔍
0 of 50 lessons completed

Your First Django Project

A Django project is a folder that holds a whole website. One command makes the folder and its starting files.

Make the project

This command makes a project named mysite. Run it in a terminal.

django-admin startproject mysite

Check the project

This command checks the project settings. It reports no issues when the settings are sound.

python manage.py check

The setup lines

These lines set up Django inside one file. A real project keeps them in settings.py.

import django
from django.conf import settings

settings.configure(DEBUG=True, SECRET_KEY="key", ROOT_URLCONF=__name__, ALLOWED_HOSTS=["*"])
django.setup()

Example

import django
from django.conf import settings

settings.configure(DEBUG=True, SECRET_KEY="key", ROOT_URLCONF=__name__, ALLOWED_HOSTS=["*"])
django.setup()

from django.core.management import call_command

urlpatterns = []

call_command("check")

Key points

  • Use django-admin startproject mysite to make a project named mysite.
  • The command makes a folder named mysite.
  • Inside the folder sits manage.py, a helper for project commands.
  • The project folder also holds settings.py, the settings file.
  • Settings are the choices a project runs with.
  • The setup lines configure Django inside one file.

In this example, the setup lines configure Django. The empty pattern list holds no addresses yet. The call_command line runs the check command. The check reports no issues, so the project settings are sound.

Note

Run project commands from inside the project folder.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

Which command makes a new Django project?