A modern, production-ready Django REST API template with authentication, email verification, and comprehensive development tools. Built with Django REST Framework, this template provides a solid foundation for building scalable web applications.
- Custom User Model - Email-based authentication with UUID support
- JWT Authentication - Secure token-based authentication with cookies
- Email Verification - Complete email verification flow with beautiful HTML templates
- Password Reset - Secure password reset with email verification
- Verified Users Only - Login restricted to verified users only
- CSRF Protection - Built-in CSRF protection with configurable settings
- Django REST Framework - Full REST API support with browsable interface
- Browsable API - Interactive web interface for testing APIs
- Django Debug Toolbar - Comprehensive debugging and profiling tools
- CORS Support - Cross-origin resource sharing configuration
- Import/Export - Data import/export functionality for admin
- Beautiful HTML Templates - Professional email templates for verification and password reset
- SMTP Configuration - Configurable email backend with TLS support
- Template Customization - Easy-to-customize email templates
- Generic Design - Templates work for any application
- Multi-Environment Support - SQLite for development, PostgreSQL for production
- Media File Handling - User upload support with proper file management
- Static Files - Optimized static file serving with WhiteNoise
- Python 3.8+
- pip
- Git
git clone https://github.com/Alien501/django-drf-template.git
cd django-templatepython -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtCreate a .env file in the root directory:
# Django Settings
SECRET_KEY=your-secret-key-here
JWT_KEY=your-jwt-key-here
ENVIRONMENT=development
COOKIE_DOMAIN=localhost
# Database (Production)
DB_NAME=your_db_name
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_HOST=your_db_host
# Email Configuration
EMAIL_HOST_USER=your-email@domain.com
EMAIL_HOST_PASSWORD=your-email-password
# Frontend URLs
VERIFICATION_URL=http://localhost:3000/verify-email
PASSWORD_RESET_URL=http://localhost:3000/reset-passwordpython manage.py makemigrations
python manage.py migratepython manage.py createsuperuserpython manage.py runserverThe project uses python-decouple for environment variable management. Key variables:
ENVIRONMENT: Set todevelopmentfor debug mode,productionfor productionSECRET_KEY: Django secret keyJWT_KEY: JWT signing keyEMAIL_HOST_USER: SMTP email addressEMAIL_HOST_PASSWORD: SMTP passwordVERIFICATION_URL: Frontend verification page URLPASSWORD_RESET_URL: Frontend password reset page URL
Development (SQLite):
- Automatically configured when
DEBUG=True
Production (PostgreSQL):
- Configure
DB_NAME,DB_USER,DB_PASSWORD,DB_HOSTin.env
The template uses SMTP for email delivery. Configure your email provider settings:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.zeptomail.in' # Change to your provider
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = config('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')POST /api/register/
Content-Type: application/json
{
"email": "user@example.com",
"password": "securepass123",
"password_confirm": "securepass123",
"first_name": "John",
"last_name": "Doe"
}POST /api/login/
Content-Type: application/json
{
"email": "user@example.com",
"password": "securepass123"
}GET /api/verify/?email=user@example.com&token=ABC123GET /api/resend_token/?email=user@example.comPOST /api/forgot_password/
Content-Type: application/json
{
"email": "user@example.com",
"password": "newpassword123"
}GET /api/forgot_password/?email=user@example.com&token=ABC123GET /api/profile/
Authorization: Bearer <jwt-token>POST /api/logout/
Authorization: Bearer <jwt-token>Visit http://localhost:8000/api/ to see the browsable API interface where you can test all endpoints interactively.
The project includes beautiful HTML email templates:
- Verification Email:
templates/email/verification_email.html - Password Reset:
templates/email/forgot_password_email.html
Customize templates by modifying these variables in authentication/models.py:
context = {
"app_name": "Your App Name",
"user_name": self.first_name,
"contact_email": "support@yourapp.com",
"contact_phone": "+1-234-567-8900",
"social_media": "@yourapp"
}When DEBUG=True, the debug toolbar provides:
- SQL query analysis
- Request/response inspection
- Template rendering details
- Performance profiling
- Cache analysis
Access at: http://localhost:8000/__debug__/
- Browsable API: Interactive web interface at each endpoint
- Admin Interface:
http://localhost:8000/admin/ - API Root:
http://localhost:8000/api/
-
Environment Variables
ENVIRONMENT=production SECRET_KEY=your-production-secret-key JWT_KEY=your-production-jwt-key
-
Database
- Configure PostgreSQL connection
- Run migrations:
python manage.py migrate
-
Static Files
python manage.py collectstatic
-
Security
- Set
DEBUG=False - Configure
ALLOWED_HOSTS - Use HTTPS in production
- Set secure cookie settings
- Set
-
Email
- Configure production SMTP settings
- Update verification URLs to production domain
django-template/
βββ AppName/ # Main project settings
β βββ settings.py # Django settings
β βββ urls.py # Main URL configuration
β βββ wsgi.py # WSGI application
βββ authentication/ # Authentication app
β βββ models.py # User model and related models
β βββ views.py # API views
β βββ serializers.py # DRF serializers
β βββ urls.py # Authentication URLs
β βββ authentication.py # Custom authentication
βββ templates/ # Email templates
β βββ email/
β βββ verification_email.html
β βββ forgot_password_email.html
βββ utils/ # Utility functions
β βββ send_mail.py # Email sending utilities
βββ static/ # Static files
βββ media/ # User uploaded files
βββ requirements.txt # Python dependencies
βββ manage.py # Django management script
βββ README.md # This file
- JWT Authentication: Secure token-based authentication
- Email Verification: Prevents unauthorized account creation
- Password Validation: Django's built-in password validators
- CSRF Protection: Cross-site request forgery protection
- CORS Configuration: Controlled cross-origin requests
- Secure Cookies: HttpOnly and SameSite cookie settings
- Create new app:
python manage.py startapp your_app - Add to
INSTALLED_APPSinsettings.py - Create models, views, serializers
- Add URLs to main
urls.py
Modify the User model in authentication/models.py:
class User(AbstractUser):
# Add your custom fields here
phone_number = models.CharField(max_length=15, blank=True)
date_of_birth = models.DateField(null=True, blank=True)Modify the CSS in email templates:
templates/email/verification_email.htmltemplates/email/forgot_password_email.html
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Commit changes:
git commit -am 'Add feature' - Push to branch:
git push origin feature-name - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions:
- Check the Django documentation
- Review the Django REST Framework docs
- Open an issue in the repository
- Add user profile management
- Implement social authentication
- Add API rate limiting
- Create comprehensive test suite
- Add Docker support
- Implement caching layer
- Add API documentation with drf-spectacular
Built with β€οΈ using Django and Django REST Framework