If you're starting a new Django project and want to set it up with popular tools like Celery, Redis, PostgreSQL, and other essential packages, this guide will walk you through the initial setup process. We'll cover creating a virtual environment, installing dependencies, starting the project, and preparing your application structure.
Step 1: Create a Virtual Environment
A virtual environment helps isolate your project’s dependencies from your global Python installation, which is crucial for managing different project requirements.
Step 2: Activate the Virtual Environment
Activate the environment depending on your operating system:
On Windows:
On macOS/Linux:
Step 3: Install Django and Required Packages
Install Django along with several useful packages for background task processing, database support, image handling, environment variable management, and form customization:
Here’s a quick rundown of what each package is used for:
-
Django
: The web framework. -
Celery
: Asynchronous task queue/job queue. -
Redis
: Broker for Celery tasks. -
django-oauth-toolkit
: For implementing OAuth2 provider. -
psycopg2-binary
: PostgreSQL database adapter. -
django-storages
: For managing media/static files in cloud storage. -
django-crispy-forms
: Enhanced form rendering. -
python-dotenv
: Loads environment variables from a.env
file. -
Pillow
: Python Imaging Library (required for image fields).Step 4: Start Your Django Project
Create your new Django project in the current directory:
Step 5: Create Django Apps
Now, set up the structure of your project by creating key apps. This helps keep your project modular and organized.
Step 6: Make Initial Migrations
Once your apps are created and models (if any) are defined, generate the initial database schema:
Step 7: Create a Superuser
Finally, create a superuser account to access the Django admin interface:
Follow the prompts to enter a username, email, and password.
Conclusion
You've now successfully set up a Django project complete with background task processing (Celery + Redis), PostgreSQL support, and a clean app structure. From here, you can start building out the functionality of each app and configure your project settings (such as database connections, static/media files, and third-party integrations).
And that's it you are ready to go with this setup. Your database connection is ready you can work with it.
Learn How to deploy django application in shared hosting
Learn How to connect the Mysql database on our Django project in Cpanel
There is no comment yet!