Polls Project: Build Your First Django App, Part 1

Updated: July 20, 2025, 09:28 PM IST

Let’s learn by creating an app. Throughout this tutorial, we’ll walk you through the creation of a basic poll application. We'll guide you through each essential step, from installing Django and understanding the project structure to running your development server and wiring up your first views and URLs. Once you've got your first app running, we'll show you how to enhance it and what's next on your Django journey, including a more advanced library management system. Let's dive in and build something real!

Build Your First Django App, Part 1

It’ll consist of two parts:

  • A public site that lets people view polls and vote in them.
  • An admin site that lets you add, change, and delete polls.

What This Article Will Cover

  • How to verify and install Django
  • Creating a Django project and understanding the file structure
  • Starting the development server
  • Creating your first app: the Polls application
  • Writing your first Django view and URLconf
  • Adding your app to INSTALLED_APPS
  • Testing your basic Django app in the browser
  • Next steps: Enhancing the Polls app

Step 1: Create a Django Project Folder:

  • Create a folder for your tutorial project:
bash
Copy Copied!
mkdir polls_project 
cd polls_project

Step 2: Create and activate a virtual environment in Python:

On Windows:

bash
Copy Copied!
python -m venv venv
venv\Scripts\activate

On macOS/Linux:

bash
Copy Copied!
python3 -m venv venv
source venv/bin/activate

To deactivate the virtual environment (on any OS), simply run:

bash
Copy Copied!
deactivate

Step 3: Verify and Install Django

  • Open your terminal and check if Django is installed:
bash
Copy Copied!
python -m django --version
  • If Django is not installed, follow the Django installation guide.
  • Ensure you're using Python 3.10 or later for Django 5.2 or newer.

bash
Copy Copied!
python -m pip install Django
bash
Copy Copied!
pip list

Step 4: Create a Django Project

1. Start a new project:

bash
Copy Copied!
django-admin startproject polls_project

2. Navigate into the project folder

bash
Copy Copied!
cd polls_project

Project structure created (inside polls_project

bash
Copy Copied!
manage.py 
polls_project/     
 __init__.py
 settings.py
 urls.py
 asgi.py
 wsgi.py

  • This is separate from the venv/ folder.
  • You typically keep venv/ outside the project directory, like this:

venv/

polls_project/

  • manage.py : Command-line utility for your Django project.
  • polls_project/ : Contains settings, URLs, WSGI, and ASGI entry points

Step 5: Run the Development Server

Run your server to confirm everything works:

Project Path Tip: To run the server, make sure you're in the same directory as manage.py (usually the project root) and that your virtual environment (venv) is activated.

bash
Copy Copied!
python manage.py runserver

Visit http://127.0.0.1:8000 in your browser. You should see the Django welcome page.

Step 6: Create the Polls App

Generate your first app:

bash
Copy Copied!
python manage.py startapp polls

This creates the folder structure for the app.

Your polls directory will now include models, views, admin, and other essential files.

Step 7: Write Your First View

Edit polls/views.py:

bash
Copy Copied!
from django.http import HttpResponse

def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")

Step 8: Create URLs for the Polls App

In polls/urls.py (create this file):

bash
Copy Copied!
from django.urls import path
from . import views

urlpatterns = [
    path("", views.index, name="index"),
]

Update polls_project/urls.py to include the polls app:

bash
Copy Copied!
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path("polls/", include("polls.urls")),
    path("admin/", admin.site.urls),
]

Step 9: Add the App to Installed Apps

Open polls_project/settings.py and add 'polls' to the INSTALLED_APPS list:

bash
Copy Copied!
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'polls',  # 👈 Add this line
]

Visit http://127.0.0.1:8000/polls/ to see your first Django-powered page!

Best Approach/Recommendation

Here are a few key tips to implement what you’ve learned:

  • Keep practicing by tweaking your polls app — add questions, forms, or templates.
  • Break down the official Django tutorial into digestible steps to avoid overwhelm.
  • Don’t skip reading error messages — they're great learning tools.
  • Use virtual environments to manage dependencies and keep projects isolated.

Conclusion & What to Do Next

You’ve successfully created your first Django project and built a basic app from scratch. That’s a huge milestone in your web development journey!

📘 First, we’ll enhance this Polls project by adding templates, models, and database integration.

📚 Coming Up Next: We’ll guide you through building a more advanced project—the Local Library Management System, based on the MDN Django Tutorial. This is a great next step to practice database relationships, user authentication, and admin-level control in Django.

Happy coding with Django!