A beginner-friendly Django project created for learning and understanding the fundamentals of Django web framework.
- Project Overview
- Prerequisites
- Project Setup
- Project Structure
- Running the Project
- Creating Your First App
- Pushing to GitHub
This is an educational Django project designed to help beginners understand:
- Django project and app structure
- URL routing and views
- Template rendering
- Static files management
- Database migrations
Before you begin, ensure you have the following installed:
- Python 3.8 or higher
- pip (Python package manager)
- Git
-
Open Terminal in VS Code (
Ctrl + ``) -
Create a new Django project:
django-admin startproject project_name cd project_name -
Create a new Django app:
python manage.py startapp app_name
-
Register the app in
project_name/settings.py:INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'app_name', # Add your app here ]
# Apply migrations to create database tables
python manage.py migrate
# Run the development server
python manage.py runserverVisit http://127.0.0.1:8000/ in your browser to see the project running.
django_project/
│
├── app_name/ # Your Django app
│ ├── migrations/
│ ├── templates/
│ │ └── home.html # HTML templates
│ ├── static/
│ │ ├── css/ # CSS files
│ │ ├── js/ # JavaScript files
│ │ └── images/ # Image assets
│ ├── views.py # View functions
│ ├── urls.py # App-level URL routing
│ ├── models.py # Database models
│ ├── admin.py # Admin configuration
│ └── apps.py
│
├── project_name/ # Project configuration
│ ├── settings.py # Project settings
│ ├── urls.py # Main URL routing
│ ├── asgi.py
│ └── wsgi.py
│
├── manage.py # Django management script
├── db.sqlite3 # Database file (SQLite)
└── README.md # This file
Create a simple view function:
# app_name/views.py
from django.shortcuts import render
def home(request):
"""Display the home page"""
return render(request, 'home.html')Configure URL routing:
# app_name/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name='home'),
]Then include app URLs in main project:
# project_name/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('app_name.urls')),
]# Start the development server
python manage.py runserver
# Access the application
# Open browser and go to: http://127.0.0.1:8000/git initCreate a .gitignore file in your project root:
# Django
*.pyc
__pycache__/
*.py[cod]
*$py.class
*.so
db.sqlite3
*.log
*.pot
venv/
env/
.DS_Store
.vscode/
.env
git add .
git commit -m "Initial Django project setup"- Go to GitHub.com
- Click New Repository
- Name it (e.g.,
django-learning-project) - Click Create Repository
# Add remote repository
git remote add origin https://github.com/your-username/django-learning-project.git
# Rename branch to main (if needed)
git branch -M main
# Push to GitHub
git push -u origin main- This is a learning project for educational purposes
- Always use virtual environment for Django projects
- Keep
SECRET_KEYand sensitive data in.envfile - Test your code frequently during development
Created for Django learning purposes
Happy Learning! 🎓