Deploy Django with PostgreSQL

How to deploy a Django application with the PostgreSQL database with Qovery

This tutorial show you how to deploy your Django application with PostgreSQL database. Let's go!

Steps to deploy Django with Qovery

  • Sign in to the Qovery web interface.

    Qovery Sign-up page

  • Django application

    Django sample application

    Get a copy of the sample source code of Django sample project by forking it.

    To deploy your Django application connected to a PostgreSQL, you can use our sample code and follow the configuration steps.

    In this example we are using PostgreSQL v11.5.

    1. Create a new project

      Migrate from Heroku

    2. Create a new environment

      Migrate from Heroku

    3. Create a new application

      To follow the guide, you can fork and use our repository

      Use the forked repository (and branch master) while creating the application in the repository field:

      Migrate from Heroku

    4. Select application port

      After the application is created:

      • Navigate application settings
      • Select Port
      • Add port 8000

      Port

    5. Use Dockerfile

      In the settings General section, set Build Mode to Dockerfile and set Dockerfile path as "Dockerfile". Then save your change.

    PostgreSQL

    1. Deploy a PostgreSQL database

      In your environment view, click on Add and Database buttons:

      Template DB Django

      In the popup window while adding a database, choose your name, select PostgreSQL and 11.5 version.

      Template DB

      In the end, click on your added database - in the new screen you'll be able to find the Deploy button:

      Template DB

    2. Connect your Django application to PostgreSQL

      Credentials of your PostgreSQL database are available via Environment Variables and Secrets. Qovery injects environment vars at the runtime.

      You can learn more about environment variables and secrets here.

      To list all the environment variables available to your Django application, you can open Environment Variables and Secret tabs in your application window:

      Secret

    Deploy your application

    All you have to do now is to navigate to your application and click Deploy button

    Deploy App

    That's it. Watch the status and wait till the app is deployed.

    Congratulations! Your environment with Django application and PostgreSQL database should be in progress.

    Trigger a new deployment

    Now, you can play with the sample Django application and commit & push your changes. Qovery detects your actions and triggers new builds and application deployments. Any change you make will be reflected in your deployed application automatically.

    Conclusion

    Congratulations! Now, you know how to deploy your Django app with PostgreSQL in just a few steps.

    Do you have any feedback about this tutorial? Let us know what you think on Discord, and join our wonderful dev community of +5500 devs.

    Tutorial