A comprehensive Django blog application built from scratch, documenting the complete learning journey from basic setup to advanced features like user authentication, authorization, and file uploads.
This repository contains a fully functional blog application built with Django, featuring user authentication, post creation with image uploads, and a complete admin interface. The project serves as a practical learning resource for Django fundamentals.
-
User Management
- User registration with automatic login
- Login/logout functionality
- Session management
- Password validation and security
-
Blog Posts
- Create, read, and display blog posts
- Rich text content with titles and body
- SEO-friendly slugs for URLs
- Image banner uploads
- Author attribution
- Automatic date/time tracking
-
Authorization & Security
- Login-required decorators for protected views
- CSRF protection on all forms
- Conditional navigation based on authentication
- Secure file upload handling
-
Admin Interface
- Django admin for content management
- Model registration
- Easy post creation and editing
- Framework: Django 5.2
- Database: SQLite (development)
- Python: 3.12+
- Image Processing: Pillow
- Frontend: HTML5, CSS3, JavaScript (vanilla)
myproject/
βββ myproject/ # Project configuration
β βββ settings.py # Main settings
β βββ urls.py # Root URL configuration
β βββ views.py # Project-level views
βββ posts/ # Blog posts app
β βββ migrations/ # Database migrations
β βββ templates/ # App templates
β βββ admin.py # Admin configuration
β βββ forms.py # Custom forms
β βββ models.py # Post model
β βββ urls.py # App URL patterns
β βββ views.py # Post views
βββ users/ # User authentication app
β βββ templates/ # User templates
β βββ urls.py # Auth URL patterns
β βββ views.py # Auth views
βββ templates/ # Project-level templates
β βββ layout.html # Base template
β βββ home.html
β βββ about.html
βββ static/ # Static files
β βββ css/
β βββ js/
βββ media/ # User uploads
βββ db.sqlite3 # Database
βββ manage.py # Django CLI
- Python 3.12 or higher
- pip (Python package manager)
- Virtual environment (recommended)
-
Clone the repository
git clone https://github.com/yourusername/django-blog.git cd django-blog -
Create and activate virtual environment
# On macOS/Linux python -m venv env_site source env_site/bin/activate # On Windows python -m venv env_site env_site\Scripts\activate
-
Install dependencies
pip install django pillow
-
Apply migrations
cd myproject python manage.py migrate -
Create superuser
python manage.py createsuperuser
-
Run development server
python manage.py runserver
-
Access the application
- Main site:
http://127.0.0.1:8000/ - Admin interface:
http://127.0.0.1:8000/admin/ - Posts:
http://127.0.0.1:8000/posts/
- Main site:
This project was built through a structured 12-lesson learning journey:
- Lesson 1-2: Project setup, apps, and templates
- Lesson 3: Models and migrations
- Lesson 4: Django ORM basics
- Lesson 5: Django admin interface
- Lesson 6: URLs, slugs, and page routing
- Lesson 7: Image uploads and media files
- Lesson 8: Creating the users app (Challenge)
- Lesson 9: User registration forms
- Lesson 10: User authentication and login
- Lesson 11: Authorization and access control
- Lesson 12: Custom forms and post creation
Detailed lesson notes are available in the lesson*.md files.
- Model field types and parameters
- ForeignKey relationships
- Database migrations workflow
- Django ORM queries
- Function-based views
- URL routing and namespacing
- Path converters
- Request/response handling
- Template inheritance
- Template tags and filters
- Static files integration
- Conditional rendering
- ModelForm creation
- Form validation
- File upload handling
- CSRF protection
- User registration
- Login/logout functionality
- Session management
- Login-required decorators
- Access control with decorators
- Conditional navigation
- User permissions
- "Next" parameter handling
- Log in to the application
- Click the "New Post" link (π)
- Fill in the form:
- Title
- Body content
- Slug (URL-friendly)
- Banner image (optional)
- Submit the form
- Navigate to registration page (π)
- Enter username and password
- Confirm password
- Automatic login after successful registration
- Access
/admin/ - Log in with superuser credentials
- Manage posts, users, and other content
- CSRF protection on all forms
- Password hashing and validation
- Login-required decorators for protected views
- Secure session management
- File upload validation
- SQL injection protection (Django ORM)
# posts/models.py
class Post(models.Model):
# ... existing fields
excerpt = models.TextField(max_length=200, blank=True)
def __str__(self):
return self.titleThen run:
python manage.py makemigrations
python manage.py migrateEdit templates in templates/ or app/templates/ directories. The base template layout.html controls the overall site structure.
This is a learning project, but suggestions and improvements are welcome! Feel free to:
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request
This project is open source and available under the MIT License.
Ankit Talukder
- GitHub: @ankit2061
- Django Software Foundation
- https://youtu.be/Rp5vd34d-z4?si=Nu7dJxKsEoQ0MsL8
- Python community
- All contributors to Django documentation
If you have questions or need help:
- Check the lesson notes (lesson*.md files)
- Review Django documentation
- Open an issue on GitHub
Note: This is a learning project for educational purposes. For production deployment, additional security measures and configurations are recommended.