Home > OS >  Bad Request (400) in django web app in Azure App service while adding Custom Domain
Bad Request (400) in django web app in Azure App service while adding Custom Domain

Time:01-08

In the Azure app service my Website is working fine with something.azurewebsites.net with the following code

ALLOWED_HOSTS = [os.environ['WEBSITE_HOSTNAME']] if 'WEBSITE_HOSTNAME' in os.environ else []

But while adding a custom domain, it is showing as Bad Request (400). I think the problem relies on the Allowed host, and the Django app is not allowing my custom domain. I couldn't find a solution or a perfect line of code to resolve this issue.

CodePudding user response:

Have you set up the custom domain in Azure? To do this, you can follow the steps in the Azure documentation:

https://docs.microsoft.com/en-us/azure/app-service/configure-custom-dns-web-site#map-a-custom-dns-name-to-an-azure-web-app

This will involve adding a CNAME record for your custom domain that points to your Azure app's default domain.

CodePudding user response:

ALLOWED_HOSTS = [os.environ['WEBSITE_HOSTNAME'],os.environ['CUSTOM_HOSTNAME']]

CUSTOM_HOSTNAME should be added to the application configuration in azure.

Eg: CUSTOM_HOSTNAME: www.example.com

  • Related