Deploy a Django project

NOTE: If you are using Django 1.x, you need to replace the python3 command with python.

NOTE: Bitnami documentation usually assumes that server console commands are executed under the bitnami user account. However, when connecting through a browser SSH console, you may be logged in under a different user account. To switch to the bitnami user account, use the command sudo su - bitnami.


For development, use the standalone server in Django by executing the following command inside your project folder:

$ python3 runserver SERVER-IP:PORT

You should now be able to browse to your project at http://SERVER-IP/APP.

SERVER-IP and PORT are optional parameters. will be used by default if you don’t specify any of them. If you plan to remotely access the server, you should use the IP address, or the actual server IP address.

IMPORTANT: Remember to open the port used by the Django server in the server firewall. Refer to the FAQ for more information.


For a production environment, we recommend configuring Apache with the mod_wsgi module before starting to serve your application (already installed and activated by default).

  • First, modify the WSGI application script file at /opt/bitnami/apps/django/django_projects/PROJECT/PROJECT/ Remember to replace PROJECT with the actual path and name to your Django project.

TIP: If you are experiencing problems when editing the above file, check if the permissions in your stack are set properly.

Although the exact content may be different depending on your Django version, ensure that the content is similar to the code below and that you add your project to the path with sys.path.append.

    import os
    import sys
    os.environ.setdefault("PYTHON_EGG_CACHE", "/opt/bitnami/apps/django/django_projects/myproject/egg_cache")
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PROJECT.settings")
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()
  • Create a conf/ folder in the /opt/bitnami/apps/django/django_projects/PROJECT/ directory.

    $ mkdir /opt/bitnami/apps/django/django_projects/PROJECT/conf
  • Create the following files:

    $ touch /opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-prefix.conf
    $ touch /opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-app.conf
  • On Linux, you can run the application with mod_wsgi in daemon mode. Add the following code in /opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-app.conf:

        WSGIDaemonProcess wsgi-djangostack   processes=2 threads=15    display-name=%{GROUP}
    <Directory "/opt/bitnami/apps/django/django_projects/PROJECT/PROJECT">
        Options +MultiViews
        AllowOverride All
        <IfVersion >= 2.3>
            Require all granted
        WSGIProcessGroup wsgi-djangostack
        WSGIApplicationGroup %{GLOBAL}
    Alias /PROJECT/static "/opt/bitnami/apps/django/lib/pythonA.B/site-packages/Django-X.Y.Z-pyA.B.egg/django/contrib/admin/static"
    WSGIScriptAlias /PROJECT '/opt/bitnami/apps/django/django_projects/PROJECT/PROJECT/'

    NOTE: Where A.B is the Python version (for example 3.6) and X.Y.Z is the Django version (for example 2.0.2).

  • In the /opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-prefix.conf file, add this code:

    Include "/opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-app.conf"
  • Add the line below to the /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf file:

    Include "/opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-prefix.conf"
  • Edit the /opt/bitnami/apps/django/django_projects/PROJECT/PROJECT/ file and update the ALLOWED_HOSTS variable with the IP address of your server, as in the example below:

    ALLOWED_HOSTS = ['SERVER-IP', 'localhost', '']
  • Restart the Apache server:

    $ sudo /opt/bitnami/ restart apache

You should now be able to browse to your project at http://SERVER-IP/PROJECT/APP.

Database configuration

If you wish to configure a database for your project, configure the file with the following settings. The examples below show how to configure the database connection with a database called “djangostack”.


  'default': {
      'ENGINE': 'django.db.backends.mysql',
      'NAME': 'djangostack',
      'HOST': '/opt/bitnami/mysql/tmp/mysql.sock',
      'PORT': '3306',
      'USER': 'USERNAME',


  'default': {
      'ENGINE': 'django.db.backends.postgresql_psycopg2',
      'NAME': 'djangostack',
      'HOST': '/opt/bitnami/postgresql',
      'PORT': '5432',
      'USER': 'USERNAME',


  'default': {
      'ENGINE': 'django.db.backends.sqlite3',
      'NAME': '/opt/bitnami/apps/django/django_projects/PROJECT/PROJECT/PROJECT.db'
Last modification April 8, 2020