Creating and Setting Up a Django Project

Developing a new website in Django requires a series of initial steps that can be somewhat tedious and confusing when getting started with the framework: creating the project, setting up an application, configuring the URLs, etc. Here is a quick and easy to follow guide that can be used as reference every time you need to start a new project.

  1. Create a new directory and open a new terminal in there.

  1. Create a virtual environment and install Django:

$ python3 -m venv env
$ source env/bin/activate
(env) $ pip install django

This step can be skipped if you want to use the system's Python interpreter and Django is already installed.

  1. Create the new Django project (named myproject in this example; change as desired) using the django-admin command and enter the project folder:

(env) $ django-admin startproject myproject
(env) $ cd myproject
  1. Create a new Django app (named myapp) inside the project:

(env) $ python startapp myapp

Remember that Django distinguishes between projects and applications. An application is a Python package with a certain structure (models, views, templates, etc.). A project is (besides a Python package) a set of applications with a common configuration (for example, they might all share the same database(s)). A Django project must have at least one application configured.

  1. Open the myproject/ file with your favorite code editor and install the newly created application in the project:

    "myapp.apps.MyappConfig",  # <-- Add this element.
  1. Create some test view in the new app by writing the following inside myapp/

from django.http import HttpRequest, HttpResponse
def index(request: HttpRequest) -> HttpResponse:
    return HttpResponse("Hello, world!")
  1. Create the file myapp/ and associate the newly created view with some path:

from django.urls import path
from . import views
urlpatterns = [
    # An empty string means the home URL.
    path("", views.index, name="index")
  1. In the myproject/ file (which is not the same as myapp/!) we will probably find something like:

from django.contrib import admin
from django.urls import path
urlpatterns = [

Add the URLs defined by your application:

from django.contrib import admin
from django.urls import path, include
urlpatterns = [
    path("", include("myapp.urls"))
  1. Start the Django development server:

(env) $ python runserver
  1. Go to and watch the result of your view:


That's it! We already have a fully configured Django project to start developing.