Getting Started with Django: Build Your First Web Application
Django is a powerful and easy-to-use web framework written in Python. It helps you build secure, scalable, and maintainable web applications quickly by providing ready-made components.
If you’re new to Django, this guide will get you started with the basics — from installation to running your first project.
What Is Django?
Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. It comes with:
-
An ORM (Object-Relational Mapper) to work with databases easily
-
Built-in admin interface for managing site content
-
Secure authentication system
-
URL routing and templating engine
-
Tools for handling forms, sessions, and more
️ Step 1: Install Django
First, make sure you have Python installed (version 3.8+ recommended). Then, install Django using pip:
To verify the installation, run:
️ Step 2: Create a Django Project
Create a new project named myproject:
This sets up the basic directory structure and files.
Step 3: Run the Development Server
Start the server with:
Open your browser and go to http://127.0.0.1:8000/. You should see the default Django welcome page — congratulations, your first Django project is running!
Step 4: Create a Django App
Django projects are made of multiple apps — components handling specific functionality.
Create an app called blog:
Step 5: Connect Your App to the Project
Add the app to your project by editing myproject/settings.py and adding 'blog' to the INSTALLED_APPS list.
Step 6: Define a View
Create a simple view in blog/views.py:
️ Step 7: Configure URL Routing
Create a new file blog/urls.py:
Then, include it in your project’s main urls.py (myproject/urls.py):
Step 8: Test Your App
Restart your server (python manage.py runserver if it’s stopped), and go to http://127.0.0.1:8000/. You should see “Hello, Django!” displayed.
Summary
-
Install Django with
pip install django. -
Create a project using
django-admin startproject. -
Run the server and check the welcome page.
-
Create an app to organize features.
-
Write views to handle requests.
-
Set up URL routing to connect views to web addresses.
