Bitnami Django for Microsoft Azure

Django is an open source Web development framework written in Python. It is easy to learn, highly scalable and built for security.

How to create a new superuser?

You can easily create a superuser account to access the Django admin site by following these steps, assuming that the projects folder is located at /opt/bitnami/apps/django/django_projects.

  • Change to your project folder:

     $ cd /opt/bitnami/apps/django/django_projects/PROJECT
  • Create a new superuser:

     $ python createsuperuser
  • Wait for the prompt and fill the required information to set up a new superuser.

How to deploy a Django project?


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

$ python runserver SERVER-IP:PORT

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/PROJECT/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.

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

      $ sudo touch /opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-prefix.conf
      $ sudo 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}
      WSGIScriptAlias /PROJECT '/opt/bitnami/apps/django/django_projects/PROJECT/PROJECT/'
      <Directory "/opt/bitnami/apps/django/django_projects/PROJECT/PROJECT/">
          WSGIProcessGroup wsgi-djangostack
          WSGIApplicationGroup %{GLOBAL}
          <IfVersion < 2.3 >
              Order allow,deny
              Allow from all
          <IfVersion >= 2.3>
              Require all granted
  • 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"
  • Add the line below to the /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf file:

      Include "/opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-vhosts.conf"
  • Edit the /opt/bitnami/django/django_projects/PROJECT/conf/httpd-vhosts.conf file and replace the domain within the ServerName and ServerAlias directives with the correct domain name.
  • Restart the Apache server.

      $ sudo /opt/bitnami/ restart restart apache

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

How to configure a database for your project?

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'

How to create a new Django project?

The projects folder is located at /opt/bitnami/apps/django/django_projects.

Follow the steps below:

  • Change to your projects folder and run the following command to create a new project. Replace the PROJECT placeholder with the name of your project in this and all subsequent commands.

     $ sudo startproject PROJECT
  • If you wish to create a new application inside the project, execute the following commands as well. Replace the APP placeholder with the name of your application in this and all subsequent commands.

     $ cd PROJECT
     $ sudo python startapp APP

    You can check your Django version at any time by executing the following command:

     python -c "import django; print(django.get_version())"
  • Edit the /opt/bitnami/apps/django/django_projects/PROJECT/APP/ file and add this content:

     from django.http import HttpResponse
     def index(request):
       return HttpResponse("Hello world!")
  • Create the /opt/bitnami/apps/django/django_projects/PROJECT/APP/ file and add these lines to it:

     from django.conf.urls import url
     from . import views
     urlpatterns = [
       url(r'^$', views.index, name='index'),
  • Edit the /opt/bitnami/apps/django/django_projects/PROJECT/PROJECT/ file and add this line to the list of URL patterns.

     url(r'^APP/', include('APP.urls')),

    For example, your file should look like this:

     url(r'^admin/', include(,
     url(r'^APP/', include('APP.urls')),
     url(r'^$', default_urlconf),
  • Restart Apache.

     $ sudo /opt/bitnami/ restart apache

You should now be able to see your new application at http://SERVER-IP/PROJECT/APP.

If you prefer to use the standalone server in Django, refer to this section. Note that in this case, you will need to create an SSH tunnel to port 8000 (or the port configured for the standalone server) following these instructions. In this case, you should be able to see your new application at http://localhost:8000/APP.

To get started with Django, check the official Django documentation for the version that you are using.

How to upgrade Django's Python package?

NOTE: Before upgrading Django, make sure that your Django applications are compatible with the new version.

Follow the steps below:

  • Execute this command from the uncompressed directory:

     $ sudo pip install --upgrade Django --install-option="--prefix=/opt/bitnami/apps/django"

    If you want a specific version of Django (not the latest one), add the version number as shown below:

     $ sudo pip install --upgrade Django==1.6.5 --install-option="--prefix=/opt/bitnami/apps/django"
  • Edit the script (usually in /opt/bitnami/apps/django/bin) and change the first line to use python instead of .python2.7.bin: