Open In App

How to Create a Project in Django

Last Updated : 12 Nov, 2025
Comments
Improve
Suggest changes
66 Likes
Like
Report

A Django project is the main folder structure for a web application, containing settings, URLs, and apps. It sets up the environment for development.

Before starting a Django project, it is important to create a virtual environment. A virtual environment isolates project dependencies, ensuring that packages installed for one project do not affect others and preventing version conflicts.

Step 1: Setup Virtual Environment

1. Create a virtual environment:

  • On Windows (PowerShell):

python -m venv venv

  • On macOS/Linux:

python3 -m venv venv

This creates a virtual environment folder named venv. The folder can have any name.

2. Activate the virtual environment:

  • On Windows (PowerShell):

.\venv\Scripts\activate

  • On macOS/Linux:

source venv/bin/activate

After activation, the terminal prompt displays the virtual environment name (e.g, (venv)), indicating that the environment is 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. and 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

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

1. Import view at the top:

from projectName.views import hello_geeks

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

Python
from django.urls import path
from projectName.views import hello_geeks

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

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

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

File-structure-of-the-project
File structure of the project

Step 5: Run the Development Server

Ensure the virtual environment is activated, then start the Django development server:

python manage.py runserver

In web browse, visit:

http://127.0.0.1:8000/geek/

The message "Hello Geeks" should be displayed.

image
Snapshot of /geeks url

Explore