Django Project Template
Overview
This Django Project Template is designed to provide developers with a robust and scalable starting point for web application projects. It includes a pre-configured structure and essential tools, allowing you to focus on developing unique features for your application.
Prerequisites
- Git
- Python 3.x
- pip (Python package manager)
- Virtual environment tool (e.g., venv, virtualenv)
Django Project Setup
Follow these steps to set up the Django project.
-
Clone the Repository: Use Git to clone the project repository to your local machine. Navigate into the cloned directory.
git clone https://github.com/omargawdat/Gawdat_Django_Template.git
-
Change the Project Name:
- Rename the project directory to your desired project name.
-
Change the App Name:
- Rename the app directory to your desired app name.
- Update all references from the old app name to the new one in the project files.
-
Create and Activate a Virtual Environment:
- Inside the project directory, create a virtual environment using Python.
python3 -m venv venv
- Activate the virtual environment.
- On Windows:
venv\Scripts\activate
- On Unix or MacOS:
source venv/bin/activate
- On Windows:
- Inside the project directory, create a virtual environment using Python.
-
Install Dependencies:
- Install the required Python packages from
requirements.in
.pip install -r requirements.in
- Install the required Python packages from
-
Database Migrations:
- Initialize the database schema by running migrations.
python manage.py makemigrations python manage.py migrate
- Initialize the database schema by running migrations.
-
Update .env File:
- Open the
.env
file. - put your own
SECRET_KEY
andSIGNING_KEY_JWT
variables.- secret key: https://djecrety.ir/
- signing key: https://randomkeygen.com/
- Open the
-
Remove old repo history:
rm -r .git git init
After completing these steps, your Django project should be set up and ready for further development.
Key Features
-
Robust Application Templates: The template includes pre-configured
app_one
andusers
applications, complete with advanced API versioning (v1
andv2
) support, streamlining the development process. -
Comprehensive Utilities Module: Equipped with a
helpers
directory, this template provides essential utilities such as constants, permissions, and validators, facilitating efficient code management. -
Seamless Docker Integration: Features a Dockerfile and docker-compose.yml, simplifying environment setup and deployment, ensuring consistency across various development and production scenarios.
-
Enhanced Development Tools:
createsu
: Streamlines the creation of superuser accounts with administrative privileges.load_fixtures
: Automates the loading of predefined data sets into the database.remove_migrations
: Efficiently manages and cleans database migration files, ensuring a clear migration history.
-
Comprehensive Testing Framework: A robust framework for unit, integration, and end-to-end testing, underpinning code reliability and quality assurance.
-
Scalable and Flexible Architecture: Designed for scalability, the template is easily adaptable to various project requirements, promoting long-term project growth.
-
Secure Authentication Mechanism: Implements JWT (JSON Web Tokens) for robust API endpoint security, ensuring data protection and integrity.
-
Custom User Model Implementation: Features a custom user model, utilizing email as the primary identifier for enhanced user management.
-
Efficient Custom Middleware: Includes middleware solutions for effective retrieval of user types from request headers, optimizing request handling.
-
Streamlined Dependency Management: Utilizes a
requirements.in
file for precise and organized management of project dependencies. -
Effective Version Control Practices: Configures
.gitignore
to exclude unnecessary files from version control, maintaining a clean and relevant code repository. -
Secured Environment Variable Handling: Employs a
.env
file for the safe storage of environment variables, bolstering application security. -
Integrated Debugging Tools: Incorporates the Django Debug Toolbar, offering advanced debugging capabilities during development.
-
Enhanced Admin Dashboard Experience: Integrates Jazzmin for a refined and feature-rich administrative interface, enhancing backend management.
-
Advanced Logging Capabilities: Implements a sophisticated logging system, producing JSON format error logs for improved readability and troubleshooting.
Project Structure
├── Dockerfile ├── README.md ├── apps │ ├── app_one │ │ ├── init.py │ │ ├── admin.py │ │ ├── api │ │ │ ├── v1 │ │ │ │ ├── init.py │ │ │ │ ├── serializers.py │ │ │ │ ├── urls.py │ │ │ │ └── views.py │ │ │ └── v2 │ │ │ ├── init.py │ │ │ ├── serializers.py │ │ │ ├── urls.py │ │ │ └── views.py │ │ ├── apps.py │ │ ├── helpers │ │ │ ├── init.py │ │ │ ├── constants.py │ │ │ ├── permissions.py │ │ │ ├── signals.py │ │ │ └── validators.py │ │ ├── migrations │ │ │ ├── init.py │ │ ├── models.py │ │ ├── services │ │ └── tests ├── common │ ├── init.py │ ├── admin_helpers.py │ ├── base_models.py │ ├── management │ │ ├── init.py │ │ └── commands │ │ ├── createsu.py │ │ ├── load_fixtures.py │ │ └── remove_migrations.py │ ├── normal_urls.py │ ├── normal_views.py │ └── utils.py ├── docker-compose.yml ├── fixtures ├── manage.py ├── media ├── myproject │ ├── init.py │ ├── asgi.py │ ├── middleware │ │ ├── init.py │ │ └── get_user_type.py │ ├── settings │ │ ├── init.py │ │ ├── base.py │ │ ├── development.py │ │ └── production.py │ ├── urls.py │ └── wsgi.py ├── requirements.in ├── staticfiles │ ├── css │ ├── img │ └── js ├── templates └── tests ├── e2e_tests └── integration_tests
This README outlines the architecture of the Django project, explaining the role and purpose of each component in the structure.
Root Directory
- Dockerfile: Setup for Docker container.
- README.md: Documentation of the project.
- manage.py: Django utility script for administrative tasks.
- requirements.in: Python dependencies list.
- docker-compose.yml: Multi-container Docker applications configuration.
- db.sqlite3: Default SQLite database file.
- fixtures: Data fixtures for database initialization.
- media: Storage for user-uploaded files.
- staticfiles: Static assets like CSS, JavaScript, and images.
- templates: HTML templates directory.
- tests: Tests for the project, including end-to-end and integration tests.
apps
Directory
- apps: Contains Django apps.
- app_one, users: Example apps.
- init.py: Marks the directory as a Python package.
- admin.py: Django admin interface configuration.
- api: API-related files, with versioning.
- apps.py: App configuration file.
- helpers: Helper functions and classes.
- migrations: Database migration files.
- models.py: Data models.
- services: Business logic or external service interactions.
- tests: App-specific tests.
- app_one, users: Example apps.
common
Directory
- common: Shared modules and utilities.
- admin_helpers.py, base_models.py, normal_urls.py, normal_views.py, utils.py: Utility modules and base classes.
- management/commands: Custom manage.py commands.
myproject
Directory
- myproject: Core project directory.
- asgi.py, wsgi.py: Entry-points for web servers.
- settings: Settings for different environments.
- urls.py: Root URL declarations.
- middleware: Custom middleware.
Other Components
- media: User-uploaded media files.
- staticfiles: Organized static files (CSS, JS, images).
- templates: HTML templates.
- tests/e2e_tests, tests/integration_tests: End-to-end and integration tests.
This structure promotes scalability, modularity, and maintainability, suitable for a wide range of Django projects.
upcoming features
- 1-docker configurations
- 2-more commands