Create Django Web app with PostgreSQL
Before you begin
Deploy from Marketplace
This blog post describes how to get started running a Django app with postgresql from Azure marketplace . This marketplace solution creates the following resources : Web Apps on Windows and Azure Database for PostgreSQL (Preview). Log in to the Azure Portal. Launch the Django + PostgreSQL template in the Azure marketplace to get started. Provide the necessary information for web app and database to be deployed.Name | Description |
---|---|
App Name |
Enter a unique app name for your **Web App Name**. This name is used as part of the default DNS name for your app <app_name>.azurewebsites.net, so it needs to be unique across all apps in Azure. You can later map a custom domain name to your app before you expose it to your users
|
Subscription | Select a Subscription. If you have multiple subscriptions, choose the appropriate subscription. |
Resource group |
Enter a resource group. A resource group is a logical container into which Azure resources like web apps, databases that is deployed and managed. You can create a resource group or use an existing one
|
App Service Plan |
App Service plans represent the collection of physical resources used to host your apps. Select the Location and the Pricing tier. For more information on pricing, see App service pricing tier
|
Server Name | Enter a postgresql database servername |
Server admin login name | Enter a postgresql database administrator username |
Server admin password | Enter a postgresql database administrator password |
Version | Azure database for PostgreSQL(Preview) currenlty supports PostgreSQL 9.5 version |
Pricing tier | Choose Basic or Standard pricing tier. For more information on pricing, see App service pricing tier |
Database Name | Enter a database name for your web app |
Develop your application
The Django + PostgreSQL template contains the Django framework on top of which you can build your application. You can create an Django app using Kudu. To access Kudu , select your web app in the portal and click Advanced Tools -> Go . Click on Debug Console to access the CMD prompt. In the console run the following commands under wwwroot folder.env\scripts\python.exe env\scripts\django-admin.exe startapp myappThis will create myapp folder with starter Django app . For more details in Django app, see Get started with Django .
Database configuration
You can access the database information within Azure portal by clicking in Application settings -> Connection strings. It is best practice to use App Settings for storing your database information instead of hard coding it in your settings.py file. Create these app settings in Azure portal for your web app. Update DATABASES setting in local settings.py file in your application. to read from App Settings environment variables.DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': os.environ.get('DATABASENAME', ''), 'USER': os.environ.get('DATABASEUSER', ''), 'PASSWORD': os.environ.get('DATABASEPASSWORD', ''), 'HOST': os.environ.get('DATABASEHOST', ''), 'PORT': '5432', } }