Skip to content

kokleong9406/msdocs-python-django-azure-container-apps

 
 

Repository files navigation

Deploy a Python (Django) app to Azure to Azure Containers Apps

This Python app is a simple restaurant review application built with the Django framework. The app stores application data in PostgreSQL with environment variables defining the connection info.

This repo was created to be built to a Docker image and run as a container instance in Azure Container Apps. For more information, see the tutorial [Deploy a Python web app on Azure Container Apps with GitHub Actions][https://learn.microsoft.com/azure/developer/python/tutorial-deploy-python-web-app-azure-container-apps-01].

This Python web app repo can also be used in other ways:

If you need an Azure account, you can create on for free.

A Flask sample application with similar functionality is at https://github.com/Azure-Samples/msdocs-python-flask-azure-container-apps.

Requirements

The requirements.txt has the following packages:

Package Description
Django Web application framework.
pyscopg2-binary PostgreSQL database adapter for Python.
gunicorn WSGI HTTP Server for UNIX. Required for running containers in VS Code.
python-dotenv Read key-value pairs from .env file and set them as environment variables. In this sample app, environment variables describe how to connect to the database and storage resources. Because managed identity is used no sensitive information is included in environment variables.

This package is used in the manage.py file to load environment variables.
requests Python HTTP for Humans.
whitenoise Static file serving for WSGI applications, used in the deployed app.

This package is used in the azureproject/production.py file, which configures production settings.

Deploying to Azure Container Apps

The steps to do this are covered more completely in the tutorial [Deploy a Python web app on Azure Container Apps with GitHub Actions][https://learn.microsoft.com/azure/developer/python/tutorial-deploy-python-web-app-azure-container-apps-01]. Briefly, here are the steps:

  1. Fork and then clone locally.
  2. Build a container image from the repo.
  3. Create a PostgreSQL Flexible Server instance.
  4. Create a database on the server.
  5. Deploy the web app container to Azure Container Apps.
  6. Configure continuous deployment.

See the create_resources.sh Bash script for automating the creation of these steps.

About

Python web app using Django that can be deployed to Azure Container Apps.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 44.8%
  • HTML 35.1%
  • Shell 15.9%
  • Dockerfile 2.7%
  • CSS 1.5%