Django App Structure

This documentation is for Dash Enterprise.
Dash Enterprise is the fastest way to write & deploy Dash apps and
Jupyter notebooks.
10% of the Fortune 500 uses Dash Enterprise to productionize AI and
data science apps. Find out if your company is using Dash Enterprise

This page outlines how to configure a Django app for deployment to Dash Enterprise. For running and previewing a Django app in a Dash Enterprise workspace, see the Development App page.

Required Files

Django App Code

Your Django app’s manage.py file should be in your project’s root directory. To deploy a Django app to Dash Enterprise, you’ll also need to configure your Django project’s urls.py and settings.py files.

urls.py

The Django Admin site is not currently supported for Django apps on Dash Enterprise. To avoid possible issues, remove admin URLs from your project’s main urls.py file.

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path("", include("polls.urls")),
    # path('admin/', admin.site.urls),
]

You’ll also need to add the name of the app initialized on Dash Enterprise as part of the URL in urlpatterns.
See the initializing an app page for more details.

For example, here we initialize an app called my-django-app:

<img>

And we then add it to paths in our project’s main urls.py file:

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path("my-django-app/", include("polls.urls")),
    # path('admin/', admin.site.urls),
]

Ensure you have a path in your app that serves content at the root URL (what a user sees when they visit the app at
https://&lt;your-dash-enterprise-server&gt;/&lt;your-app-name&gt;/)

settings.py

To configure the settings.py file:

  1. Add your Dash Enterprise hostname to ALLOWED_HOSTS. If you access the Dash Enterprise portal at https://example-dash-enterprise-5-hostname.com/portal, the hostname would be example-dash-enterprise-5-hostname.com.

    python ALLOWED_HOSTS = [ &lt;dash-enterprise-hostname&gt; ]
    2. Remove django.contrib.admin, django.contrib.auth, and django.contrib.sessions from INSTALLED_APPS. These are currently unsupported on Dash Enterprise.

    python INSTALLED_APPS = [ # 'django.contrib.admin', <-- This line should be removed or commented out # 'django.contrib.auth', <-- This line should be removed or commented out 'django.contrib.contenttypes', # 'django.contrib.sessions', <-- This line should be removed or commented out 'django.contrib.messages', 'django.contrib.staticfiles', ]

  2. Remove django.contrib.auth.middleware.AuthenticationMiddleware from MIDDLEWARE. This is currently unsupported on Dash Enterprise.

    python MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', # 'django.contrib.auth.middleware.AuthenticationMiddleware', <-- This line should be removed or commented out 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ]
    4. For a production app, set DEBUG = False

For more details on settings.py, see the Django documentation.

requirements.txt or environment.yml

Describe your app’s Python dependencies in a requirements.txt file if you want Dash Enterprise to use the pip buildpack, or describe them in an environment.yml file if you want Dash Enterprise to use the Conda buildpack.

Note that adding both requirements.txt and environment.yml to your app currently causes Dash Enterprise to detect only the pip buildpack, so it is not possible to use both sets of features from these files in the same app.

Procfile

A Procfile is a required text file that tells Dash Enterprise which processes to run on
startup, like starting your app’s web server, scheduling jobs, and running background processes.

This file is always named Procfile—with no file extension. It must be placed in your app’s root directory and uses the following format:

&lt;process&gt;: &lt;command&gt;

 

Django app Procfile example

A basic Procfile for a Django app looks like this.

web: gunicorn &lt;your-django-app&gt;.wsgi

For the Django app above called mysite, this would look like this:

web: gunicorn mysite.wsgi

For more details on Django with Gunicorn see How to use Django with Gunicorn.

Optional Files

project.toml

.gitignore

.gitignore is a text file that determines which files and folders are ignored by Git.
Files listed in the .gitignore are not copied to the server when you deploy your app.

venv
*.pyc
.DS_Store
.env

Aptfile

An Aptfile can be used to install system-level packages via the APT package manager. It supports:

If an Aptfile is included in your project, an apt-get update is triggered before installing the packages.

 

Packages from standard APT repositories

Packages from APT repositories might include database drivers that your app requires.
In the following example we are installing unixodbc and unixodbc-dev:

unixodbc
unixodbc-dev

 

Specific .deb files

You can also add links to specific .deb files to be installed:

<a href="https://downloads.example.com/example.deb">https://downloads.example.com/example.deb</a>

 

Custom APT repositories

Your Aptfile can also contain additional APT
repositories:

:repo:deb <a href="https://apt.example.com/">https://apt.example.com/</a> example-distro main

Important: Dash Enterprise requires that custom APT repositories have a TLS/SSL certificate from a globally trusted certificate authority (CA).

To use APT packages in your apps when Dash Enterprise is internet-restricted, you need to specify a custom APT repository that Dash Enterprise has network access to. See an example in
Developing Apps when Dash Enterprise Is Internet-Restricted.


Additional Resources