Code Monkey home page Code Monkey logo

msdocs-python-django-container-web-app's Introduction

Deploy a Python (Django) web app container to Azure App Service (in progress)

This Python web app is a restaurant review application using the Django framework. The app is intended to be used as a container running in Azure App Service with a connection to MongoDB such as Azure Cosmos DB API for MongoDB.

Following the tutorial Containerized Python web app on Azure, you can deploy this web app to Azure, hosted in a fully managed Azure App Service. Azure managed identity enables the App Service to pull container images from an Azure Container Registry. MongoDB connection info is passed to the code through environment variables.

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

A Flask sample application with similar functionality is at Flask Container Web App.

Run and deploy options

Here are some ways you can run the sample web app in this repository.

Scenario As-is repo code Containerized app
Local environment Run repo code in virtual environment with requirements.txt. Set environment variables in shell before running. For an example, see Configure a Python virtual environment. Build image from repo and run locally in Docker container. Pass environment variables in Docker CLI command or with VS Code task definition 1. This scenario is covered in Containerized Python web app on Azure.
Azure App Service Deploy repo code to App service. Set environment variables as App Service configuration settings. See note about subpath. 2 Deploy container to Web App for Containers. Build image locally or in Azure and push to container registry like Azure Container Registry. Configure App Service to pull from registry. Set environment variables as App Service configuration settings. This scenario is covered in Containerized Python web app on Azure.
Azure Container Apps n/a Build image locally or in Azure and push to container registry like Azure Container Registry. Create a Container App with deployment from the registry. Configure environment variables for the container.

(1) The .vscode directory settings.json and tasks.json are configured either for a MongoDB local connection or an Azure Cosmos DB connection. The tasks and templates in .vscode are only used when using Visual Studio Code locally.

(2) This app was designed to be containerized and run on App Service. If you want to deploy to App Service without containerizing it, then be sure to set the subpath to the azureporject folder, which contains the manage.py file. Do that by:

  • In VS Code: F1 or CTRL + SHIFT + P to open the command palette.
  • Type "Preferences: Open Workspace Settings" and select to open.
  • In the Settings search field, enter "@id:appService.deploySubpath appser".
  • Set the subpath as "azureproject".

Environment variables

The sample code requires the following environment variables passed in as described in the scenario table above.

CONNECTION_STRING=<connection-string>
DB_NAME=restaurants_reviews
COLLECTION_NAME=restaurants_reviews

For a local MongoDB instance, the connection string is of the form mongodb://127.0.0.1:27017. An Azure Cosmos DB API for MongoDB connections string is of the form mongodb://<server-name>:<password>@<server-name>.mongo.cosmos.azure.com:10255/?ssl=true&<other-parameters>.

Requirements

The requirements.txt has the following packages:

Package Description
Django Web application framework.
gunicorn Gunicorn ‘Green Unicorn’ is a Python WSGI HTTP Server for UNIX.
pymongo The PyMongo distribution contains tools for interacting with MongoDB database from Python.
requests An HTTP library
whitenoise Static file serving for WSGI applications, used in the deployed app.

This package is used in the azureproject/settings.py file.

msdocs-python-django-container-web-app's People

Contributors

microsoft-github-operations[bot] avatar microsoftopensource avatar vmagelo avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.