Based on Django API Template
This Django API Template is designed to be robust, scalable, and secure, with features that cater to modern application development needs. Here's an overview of the advanced features and how they benefit your project:
-
Docker & Docker Compose Integration: Easily set up and scale your application using Docker containers, ensuring consistent environments across development and production.
-
Celery with RabbitMQ and Redis: Leverage Celery for asynchronous task processing, using RabbitMQ as a message broker and Redis as a backend for storing results.
-
Sentry for Error Tracking: Integrate with Sentry for real-time error tracking and monitoring, helping you identify and fix issues rapidly.
-
Django Rest Framework (DRF): Use Django Rest Framework for building RESTful APIs, with support for authentication, serialization, and more.
- DRF Spectacular for OpenAPI: Use DRF Spectacular for OpenAPI documentation, with support for customizing the schema and UI.
- DRF Simple JWT for Authentication: Use DRF Simple JWT for JSON Web Token authentication, with support for customizing token claims and expiration.
-
Django CORS Headers: Use Django CORS Headers for handling Cross-Origin Resource Sharing (CORS) headers, with support for customizing origins.
-
Django Silk for Profiling: Utilize Django Silk for profiling and monitoring Django applications, offering insights into performance and optimization.
-
Django Axes for Security: Use Django Axes for security, with support for blocking brute force attacks and monitoring login attempts.
-
AWS S3 Integration: Option to use Amazon S3 for static and media file storage, enhancing scalability and performance.
-
Scalability Options: Configure workers and threads to optimize performance under different load conditions.
-
Up-to-Date Dependencies: All dependencies are up-to-date as of the latest release. Thanks to Dependabot.
The .env
file is a central place to manage environment variables. It's pre-configured to work with Docker Compose out of the box, without any changes required for initial setup. However, for production deployment, certain secrets must be updated for security reasons.
-
Secrets:
- PostgreSQL, RabbitMQ, Django Secrets: These are critical for the security of your application. Ensure to replace the placeholder values with strong, unique passwords.
-
Ports:
- API Port and RabbitMQ Dashboard Port: Set these ports according to your infrastructure needs. They are exposed to the host machine.
-
Performance Tuning:
- Workers and Threads: Adjust these values based on your server's capacity and expected load.
-
Application Settings:
- Host and Environment: Set these to match your deployment environment.
- Debug and Logging: Control debug mode and log levels. Set
DJANGO_DEBUG
tofalse
in production. - Localization: Configure
LANGUAGE_CODE
andTIME_ZONE
as per your requirements.
-
CORS and CSRF Settings:
- Configure these settings to enhance the security of your application by specifying trusted origins.
-
Database Configuration:
- Postgres Connection: Set up the database connection using the
DATABASE_URL
variable.
- Postgres Connection: Set up the database connection using the
- Security: Always prioritize security, especially when handling environment variables and secrets.
- Scalability: Adjust the Docker and Celery configurations as your application scales.
- Monitoring: Regularly monitor the performance and health of your application using integrated tools like Sentry and Silk.
By following this guide and utilizing the advanced features, you'll be able to set up a powerful, efficient, and secure Django API environment. Happy coding!
- Clone the Repository
- Create a Virtual Environment:
python3.12 -m venv .venv
- Activate the Virtual Environment:
source .venv/bin/activate
- Environment Variables:
- Copy the example environment file:
cp .env.example .env
- Note: The API can operate without this step, but configuring the environment variables is recommended for full functionality.
- Copy the example environment file:
- Install Dependencies:
pip install -r requirements-dev.txt
- Run Migrations:
make migrate
- Start the Local Server:
make run.server.local
- Start the bot:
make run.bot.local
- Clone the Repository
- Follow the steps in the Configuration Guide to set up the
.env
file.
- Run Docker Compose:
docker compose up -d