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.

python -m venv venv

Step 2: Activate the Virtual Environment

Activate the environment depending on your operating system:

On Windows:

venv\Scripts\activate

On macOS/Linux:

source venv/bin/activate

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:

pip install django celery redis django-oauth-toolkit psycopg2-binary django-storages django-crispy-forms python-dotenv Pillow

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:

    django-admin startproject project_name .


    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.

    python manage.py startapp accounts
    python manage.py startapp analytics
    python manage.py startapp marketplace


Step 6: Make Initial Migrations

Once your apps are created and models (if any) are defined, generate the initial database schema:

python manage.py makemigrations
python manage.py migrate

Step 7: Create a Superuser

Finally, create a superuser account to access the Django admin interface:

python manage.py createsuperuser

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


hosenmdaltaf

Hosen MD Altaf

Hello! I'm Hosen MD Altaf, a passionate Software Engineer and content writer.Who's experienced in taking fullstack applications from scratch to production.Currently, I am working with python and javaScript based FullStack Web development. Over the last 2 years, I've had the opportunity to develop web applications for a handful of awesome companies / clients as a consultant and continue to do so today. My work includes developing fullstack web apps, creating backend servers,designing font-end application, small Big-data and data science projects,creating websites with python django,react.js and wordpress.I am eager to learn kew technologies and looking for new opportunitys.

Comments (0)

wave
  • There is no comment yet!

Leave Comment

wave