Django for Beginners: Step-by-Step Guide to Building Your First Web App

Django is one of the most popular Python web frameworks, designed to help developers build secure, scalable, and maintainable web applications quickly. Known for its “batteries-included” approach, Django provides built-in features like authentication, database management (ORM), and an admin panel, reducing the need for third-party libraries.

Thank you for reading this post, don't forget to subscribe!

Whether you’re building a simple blog, an e-commerce site, or a RESTful API, Django’s clean architecture and extensive documentation make it an excellent choice for beginners and professionals alike.

In this guide, we’ll cover:

  • Setting up a Django development environment
  • Creating your first Django project and app
  • Understanding Django’s MVT (Model-View-Template) architecture
  • Working with databases using Django’s ORM
  • Rendering dynamic templates
  • Deploying a basic Django application

By the end, you’ll have a solid foundation to start building your own Django-powered web applications.


Prerequisites

Before diving into Django, ensure you have:
✅ Python installed (3.9 or later recommended)
✅ Basic Python knowledge (functions, classes, modules)
✅ A code editor (VS Code, PyCharm, or Sublime Text)
✅ Familiarity with the command line

Step 1: Setting Up a Virtual Environment

Before installing Django, it’s best practice to create a virtual environment to isolate dependencies:

On macOS/Linux:

On Windows:

Once activated, install Django:

Verify the installation:

Step 2: Creating a Django Project

A Django project is the entire web application, while apps are modular components within it (e.g., a blog app, user authentication app).

To create a new project:

This generates the following structure:

Running the Development Server

Navigate into your project and start the server:

Visit http://127.0.0.1:8000/ in your browser—you should see Django’s default welcome page!

Step 3: Creating Your First Django App

A Django project can contain multiple apps. Let’s create one:

This generates:

Registering the App

Add your app to INSTALLED_APPS in myproject/settings.py:

Step 4: Creating a Simple View

view in Django processes HTTP requests and returns responses. Open myapp/views.py and add:

Mapping URLs to Views

1.  Create urls.py inside myapp:

2. Include it in the project’s urls.py:

Now, visiting http://127.0.0.1:8000/ should display “Hello, Django!”

Step 5: Using Templates for Dynamic HTML

Django uses templates to render dynamic HTML.

Create a templates folder in myapp:

Add home.html inside it:

Update views.py to render the template:

Now, the page will display “Hello from Django!” in styled HTML.

Step 6: Working with Django Models (Database)

Django’s ORM (Object-Relational Mapper) allows you to define database models using Python classes.

Creating a Model

Let’s create a Post model for a blog in myapp/models.py:

Running Migrations

Django needs to create database tables for your models:

Using Django’s Admin Panel

Django comes with a built-in admin interface.

Create a superuser:

Follow the prompts to set up an admin account.

Register the model in admin.py:

Access the admin panel at http://127.0.0.1:8000/admin/
Log in and manage your Post entries.

Step 7: Displaying Data in Templates

Let’s fetch posts from the database and display them.

Update views.py:

Modify home.html:

Now, any posts added via the admin panel will appear here!

Next Steps & Further Learning

You’ve built a basic Django app! To expand your knowledge:

  • User Authentication: Use Django’s built-in auth system.
  • Forms: Learn how to handle user input.
  • Class-Based Views (CBVs): A more structured way to write views.
  • Deployment: Host your app on platforms like Render, Railway, or PythonAnywhere.

Here’s a well-structured addition to your Django guide focusing on settings.py configurations, formatted for clarity and SEO optimization:

Essential Django settings.py Configurations for Production

When building Django applications, properly configuring your settings.py file is crucial for security, performance, and functionality. Here are key modifications you should implement:

 

1. Template Configuration

Ensure Django can find your template files:

2. Static & Media Files Setup

3. Security Settings

4. Email Configuration (Gmail Example)

5. Django Messages Framework

Configuring URLs in Django: Static & Media Files Setup

Basic URL Configuration (urls.py)

Every Django project needs proper URL routing. Here’s how to set up your main urls.py file:

or

 

Recommended Resources

Conclusion

Django is a powerful, flexible framework that simplifies web development. In this guide, we covered:
✔ Setting up a Django project
✔ Creating views & URL routing
✔ Working with templates
✔ Database models & the admin panel

Now, try building a blog, to-do app, or a simple CRM to practice!

Got questions? Drop them in the comments below! 🚀

#Django #Python #WebDevelopment #Programming #BeginnersGuide

Share on:

Hello, I am Dharmendra Yadav and I am a Python Developer with experience in web development using Django, Flask, REST API, SQL, MySQL, HTML, CSS, JavaScript, WordPress, Oracle Cloud, AWS and Git. I also write technical articles where I explain web development and Software Engineering. Facebook , Linkedin