Troubleshooting

Deploy a Django project

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

Development

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

$ python3 manage.py runserver SERVER-IP:PORT

SERVER-IP and PORT are optional parameters. 127.0.0.1:8000 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 0.0.0.0, 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](/bch/faq/administration/use-firewall/ for more information.

Production

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/wsgi.py. Remember to replace PROJECT with the actual path and name to your Django project.

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
sys.path.append('/opt/bitnami/apps/django/django_projects/PROJECT')
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.

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/myproject/myproject/settings.py*file and update the ALLOWED_HOSTS variable with the IP address of your server, as in the example below:

ALLOWED_HOSTS = ['SERVER-IP', 'localhost', '127.0.0.1']

Restart the Apache server:

$ sudo /opt/bitnami/ctlscript.sh restart apache

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

Database configuration

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