Federal Science DataHubFederal Science DataHub
  • English
  • Français
  • English
  • English
  • Français
  • English
  • Overview
  • Managing Workspaces and Users

    • Getting a workspace (only available on the GC network)
    • Estimate costs (only available on the GC network)
    • Account Setup
    • Requesting, configuring and removing tools in your workspace
    • Invite a user
    • Change a user role
    • Manage your CBR & workspace budgets
  • Storage

    • Working with Azure Storage
    • Bring Your Own Storage

      • Import AWS S3 Bucket
      • Import Azure Storage
      • Import Google Cloud Platform Storage
    • Access Storage in Databricks
    • Access Storage in Power BI
    • Use AzCopy to Interact with Storage
  • Databricks

    • Getting Started with Databricks
    • FSDH Cluster Policies
    • MLFlow: AutoML and Experiments
    • Databricks Workflows
    • Dashboarding

      • How to Dashboard in Databricks
      • Dashboarding Tool Comparison
    • External Extensions

      • Git/GitHub Integration with Databricks
      • Databricks VS Code Extension
      • Working with Conda
      • Connecting Google API to Databricks
  • PostgreSQL

    • Create and use a PostgreSQL Database
    • Add a User to PostgreSQL on FSDH
    • Access PostgreSQL in Power BI
    • PostgreSQL vs Azure Databricks Database Features
  • Web Applications

    • Hosting Web Apps on DataHub
    • Demo Apps

      • Django (Python)
      • Django Configuration for FSDH
      • Dash (Python)
      • Flask (Python)
      • Shiny (R)
      • Streamlit (Python)
  • Migrating to Production

    • Migrating Storage
    • Migrating Databricks
    • Migrating PostgreSQL
    • Migrating Web Apps
  • User Guidance

    • Account Management and Access control of workspaces
    • Backup and Recovery
    • Code Management
    • Restricted File Types on FSDH Storage
    • Workspace Monitoring
  • Terms and Conditions

Django Configuration for FSDH

If your web app is a Django web app, this guide is meant to assist you in a few further changes that you will have to make for your app to properly function on the FSDH.

Toggle "URL rewrite" On

In the App Service section of your workspace, under "Quick settings" is a switch labeled "URL rewriting" that needs to be turned on. Without this, Django may not recognize the URLs that get accessed.

Add the FSDH to the ALLOWED_HOSTS and CSRF_TRUSTED_ORIGINS

In order for the FSDH to properly render your web pages, you need to inform the server which sites are allowed to host your app. It is likely that you already have environment variables to determine these, in which case you simply need to add federal-science-datahub.canada.ca, plateforme-federale-donnees-scientifiques.canada.ca, prd.fsdh-dhsf.science.cloud-nuage.canada.ca and fsdh-proj-<your workspace name>-webapp-prd.azurewebsites.net. If you do not have environment variables for these, you can either create them or manually set them in your settings.py.

Here is an example of what setting these values inside of settings.py could look like. In this case, both are set by the same environment variable but that is in no way necessary.

ALLOWED_HOSTS = os.environ.get("ALLOWED_HOSTS","127.0.0.1").split(",")
CSRF_TRUSTED_ORIGINS = (f'https://{i}' for i in ALLOWED_HOSTS) # CSRF_TRUSTED_ORIGINS requires the strings to contain "https://".

Add the FORCE_SCRIPT_NAME in settings.py

In the settings.py file of your Django project you will need to set the FORCE_SCRIPT_NAME variable to include the "Proxy URL for development" from the Web application information section of your workspace's app service. It should resemble something like /app/<Project Name>/. Once this is applied, Django will know to prepend your internal links with the FSDH prefix.

You will also need to go to your STATIC_URL declaration in the same file and also prepend it with the same value. It should resemble something like the following.

FORCE_SCRIPT_NAME = os.environ.get("SCRIPT_NAME","")
# ... There would probably be more code in between these two lines
STATIC_URL = os.path.join(FORCE_SCRIPT_NAME, "static/")

For Django to actually apply the prefix however, it seems that the strings in the base urls.py must be formatted strings:

urlpatterns = [
    path('path/here/', views.page, name="page"), # Incorrect, not a formatted string
    path(f'path/here/', views.page, name="page"), # Correct, a formatted string
    path(f'other/path/', include("other.urls")), # Also format the strings for paths that lead to other urlpatterns, you do not need to format the strings in the other file however.
] + static(settings.STATIC_URL, document_root=settings.STATICFILES_DIRS)

Proper URL Retrieval

It is possible that some links or references might not work, if that is the case make sure that you are using Django's URL replacement features and that they are not hardcoded. For example, in your HTML/CSS/JS you would use "{% url 'home' %}" instead of "/" or "/home". In you Python code, you would use django.urls.reverse("home"). Do also make sure that you give your pages their respective names in the urls.py as it is these names that Django looks for. Without this, these URLs won't contain the script name.

Edit this page on GitHub
Last Updated: 2026-08-10, 5:16 p.m.
Previous
Django (Python)
Next
Dash (Python)