DEV Community

Samuel Lubliner
Samuel Lubliner

Posted on

Django: Creating a skeleton website

From: MDN Web Docs

Creating the library project

  • Open the terminal in a virtual or development environment
  • Navigate to the project folder
  • Run:
django-admin startproject locallibrary

cd locallibrary`
Enter fullscreen mode Exit fullscreen mode

django-admin generates:

  • a project folder
  • the file templates
  • a locallibrary sub-folder with the same name as the project folder. This is the entry point for the website.

The sub-folder entry point contains: Indicates the directory is a Python package Website settings URL-to-view mappings Web Server Gateway Interface for synchronous apps Asynchronous Server Gateway Interface Project management script that creates one or more applications.


  • Separate, reusable components of a website
  • Register the new applications
  • url/path mapper for each application

Creating the catalog application

Run this command from the same folder as

python3 startapp catalog

This creates the following folder structure:

Enter fullscreen mode Exit fullscreen mode

The migrations folder updates the database when models are modified.

Note for codespace development:

Add * wildcard to ALLOWED_HOSTS in This allows the host to run the live preview.

Register the catalog application

Add applications to INSTALLED_APPS in the project settings.

Specifying the database

SQLite is the default database. It is suitable if you don't a lot of concurrent access. Postgres requires additional setup and is more suitable for larger sites.

Other settings

TIME_ZONE can be configured.

SECRET_KEY can be changed to read from an environment variable in production.

DEBUG logs errors in a file instead of HTTP status code responses. Set to False in production.

Hook up the URL mapper

While can handle all the URL mappings, it's more common to route these mappings to the corresponding application.

The URL mappings are managed through the urlpatterns variable, which is a list of path() functions.

path() forwards requests to the module with the relative URL.

RedirectView redirects the root URL of the site.

Django does not serve static files by default. Serving CSS, JavaScript, and images can be useful for the development web server. Do not do this in production.

In the catalog folder, create and define the imported urlpatterns. Add patterns here as the application grows.

Before doing this, first run a database migration to update the database.

Running database migrations

Django uses an Object-Relational-Mapper. Django tracks the changes to model definitions and can create database migration scripts.

In the directory that contains, run

python3 makemigrations
python3 migrate

makemigrations creates the migrations.

migrate applies the migrations to the database.

Running the website

python3 runserver

Runs the development web server.

An error page is expected if there are no pages/urls defined in the the root of the site.

Top comments (0)