Skip to content

Instantly share code, notes, and snippets.

@j-thepac
Last active April 28, 2022 05:28

postgres-Django

Ref:Tutorial

Azure App Service

Creat APP

    git clone https://github.com/Azure-Samples/djangoapp
    cd djangoapp
    az webapp up \
    --resource-group DjangoPostgres-tutorial-rg \
    --location centralus \
    --plan DjangoPostgres-tutorial-plan \
    --sku F1 \
    --name djangopostgresapp

Add extension to db extension to CLI

    az extension add --name db-up   #install db-up (ref- https://gist.github.com/j-thepac/b0ab1196585cf8b9a8478e4a3c8b6aae)

Create a new Postgres instance

    az postgres up \
    --resource-group DjangoPostgres \
    --location centralus \
    --sku-name B_Gen5_1 \
    --server-name djangopostgresserver \
    --database-name pollsdb \
    --admin-user sqlusr \
    --admin-password Azure@123 \
    --ssl-enforcement Enabled

Note down DB details from console

Connect App and DB

    az webapp config appsettings set \
    --name djangopostgresapp \
    --settings DBHOST="djangopostgresserver" DBUSER="sqlusr" DBPASS="Azure@123" DBNAME="pollsdb" 

DB Migration

    az webapp ssh #open ssh 
    python manage.py migrate
    python manage.py createsuperuser # usn=root/password Pollsdb1
    #skip email 
    exit

Test :

    az webapp browse

open https://djangopostgresapp.azurewebsites.net/ (http://.azurewebsites.net/admin)

Update python file and redeploy

    Make any changes to python file
    az webapp up
    az webapp log tail

group delete

    az group delete --name DjangoPostgres --no-wait
    az group delete --name DjangoPostgres-tutorial-rg --no-wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment