Open In App

How to Create a Project in Django

Last Updated : 06 Oct, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Below is a step-by-step guide to creating and running a Django project:

Step 1: Setup Virtual Environment

1. Create a virtual environment by running the following command:

python -m venv venv

This creates a virtual environment folder named venv. You can name this folder anything, but venv is commonly used.

2. Activate the virtual environment:

  • On Windows (PowerShell):

.\venv\Scripts\activate

  • On macOS/Linux:

source venv/bin/activate

After activating, your terminal prompt should show the virtual environment name (e.g., (venv)), indicating it’s active.

3. Install Django inside the virtual environment:

pip install django

Step 2: Create the Project

Create a new Django project by running:

django-admin startproject projectName

This will create a new folder named projectName

Change into your project directory:

cd projectName

Step 3: Create a View

Inside your project folder (where settings.py and urls.py are located), create a new file named views.py.

Add the following code to views.py:

Python
from django.http import HttpResponse

def hello_geeks(request):
    return HttpResponse("Hello Geeks")

This simple view returns the string "Hello Geeks" when accessed.

Step 4: Configure URLs

Open the urls.py file inside the project folder (projectName/urls.py) and modify it as follows:

1. Import your view at the top:

from projectName.views import hello_geeks

2. Add a URL pattern inside the urlpatterns list to link to your view:

Python
from django.urls import path

urlpatterns = [
    path('geek/', hello_geeks),
]

This routes any request to /geek/ to the hello_geeks view.

After following these steps, our file structure should look like this:

djano_fs_19
File structure of the project

Step 5: Run the Development Server

1. Ensure your virtual environment is activated (repeat Step 1.2 if needed).

2. Start the Django development server by running:

python manage.py runserver

3. Open your web browser and visit:

http://127.0.0.1:8000/geek/

You should see the message "Hello Geeks" displayed.

Output:

django18
Snapshot of /geeks url

Explore