Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit focus mode

Quickstart: Create and deploy a Python web app to Azure using an azd template

  • 2024-12-16
Feedback

In this article

This quickstart guides you through the easiest and fastest way to create and deploy a Python web and database solution to Azure. By following the instructions in this quickstart, you will:

  • Choose anazd template based on the Python web framework, Azure database platform, and Azure web hosting platform you want to build on.
  • Use CLI commands to run anazd template to create a sample web app and database, and create and configure the necessary Azure resources, then deploy the sample web app to Azure.
  • Edit the web app on your local computer and use anazd command to redeploy.
  • Use anazd command to clean up Azure resources.

It should take less than 15 minutes to complete this tutorial. Upon completion, you can start modifying the new project with your custom code.

To learn more about theseazd templates for Python web app development:

Prerequisites

An Azure subscription -Create one for free

You must have the following installed on your local computer:

Choose a template

Choose anazd template based on the Python web framework, Azure web hosting platform, and Azure database platform you want to build on.

  1. Select a template name (first column) from the following list of templates in the following tables. You'll use the template name during theazd init step in the next section.

    TemplateWeb FrameworkDatabaseHosting PlatformGitHub Repo
    azure-django-postgres-flexible-acaDjangoPostgreSQL Flexible ServerAzure Container Appsrepo
    azure-django-postgres-flexible-appserviceDjangoPostgreSQL Flexible ServerAzure App Servicerepo
    azure-django-cosmos-postgres-acaDjangoCosmos DB (PostgreSQL Adapter)Azure Container Appsrepo
    azure-django-cosmos-postgres-appserviceDjangoCosmos DB (PostgreSQL Adapter)Azure App Servicerepo
    azure-django-postgres-addon-acaDjangoAzure Container Apps PostgreSQL Add-onAzure Container Appsrepo

The GitHub repository (last column) is only provided for reference purposes. You should only clone the repository directly if you want to contribute changes to the template. Otherwise, follow the instructions in this quickstart to use theazd CLI to interact with the template in a normal workflow.

Run the template

Running anazd template is the same across languages and frameworks. And, the same basic steps apply to all templates. The steps are:

  1. At a terminal, navigate to a folder on your local computer where you typically store your local git repositories, then create a new folder namedazdtest. Then, change into that directory using thecd command.

    mkdir azdtestcd azdtest

    Don't use Visual Studio Code's Terminal for this quickstart.

  2. To set up the local development environment, enter the following commands in your terminal and answer any prompts:

    azd init --template <template name>

    Substitute<template name> with one of the templates from thetables you selected in a previous step, such asazure-django-postgres-aca for example.

    When prompted for an environment name, useazdtest or any othername. The environment name is used when naming Azure resource groups and resources. Forbest results, use a short name, lower case latters, no special characters.

  3. To authenticateazd to your Azure account, enter the following commands in your terminal and follow the prompt:

    azd auth login

    Follow the instructions when prompted to "Pick an account" or log into your Azure account. Onceyou have successfully authenticated, the following message is displayed in a web page:"Authentication complete. You can return to the application. Feel free to closethis browser tab."

    When you close the tab, the shell displays the message:

    Logged in to Azure.
  4. Ensure that Docker Desktop is open and running in the background before attempting the next step.

  5. To create the necessary Azure resources, enter the following commands in yourterminal and answer any prompts:

    azd up

    Important

    Onceazd up completes successfully, the sample web app will be available on the public internet and your Azure Subscription will begin accruing charges for all resources that are created. The creators of theazd templates intentionally chose inexpensive tiers but not necessarilyfree tiers since free tiers often have restricted availability.

    Follow the instructions when prompted to choose Azure Subscription to use for payment, thenselect an Azure location to use. Choose a region that is close to you geographically.

    Executingazd up could take several minutes since it's provisioning anddeploying multiple Azure services. As progress is displayed, watch for errors. If you see errors, try the following to fix the problem:

    • Delete theazd-quickstart folder and the quickstart instructions from the beginning.
    • When prompted, choose a simpler name for your environment. Only use lower-case letters and dashes. No numbers, upper-case letters, or special characters.
    • Choose a different location.

    If you still have problems, see theTroubleshooting section at the bottom of this document.

    Important

    Once you have finished working with the sample web app, useazd down to remove all of the services that were created byazd up.

  6. Whenazd up completes successfully, the following output is displayed:

    Screenshot of successful output from the azd command line interface with a callout around the endpoint URL to view the working Relecloud application deployed in Azure.

    Copy the first URL after the word- Endpoint: and paste it into the locationbar of a web browser to see the sample web app project running live in Azure.

  7. Open a new tab in your web browser, copy the second URL from the previous step and paste it intothe location bar. The Azure portal displays all of the services in your newresource group that have been deployed to host the sample web app project.

Edit and redeploy

The next step is to make a small change to the web app and then redeploy.

  1. Open Visual Studio Code and open theazdtest folder created earlier.

  2. This template is configured to optionally use Dev Containers. When you see the Dev Container notification appear in Visual Studio Code, select the "Reopen in Container" button.

  3. Use Visual Studio Code's Explorer view to navigate tosrc/templates folder, and open theindex.html file. Locate the following line of code:

    <h1>Welcome to ReleCloud</h1>

    Change the text inside of the H1:

    <h1>Welcome to ReleCloud - UPDATED</h1>

    Save your changes.

  4. To redeploy the app with your change, in your terminal run the following command:

    azd deploy

    Since you're using Dev Containers and are connected remotely into the container's shell, don't use Visual Studio Code's Terminal pane to runazd commands.

  5. Once the command completes, refresh your web browser to see the update. Depending on the web hosting platform being used, it could take several minutes before your changes are visible.

    You're now ready to edit and delete files in the template. For more information, seeWhat can I edit or delete in the template?

Clean up resources

  1. Clean up the resources created by the template by running theazd down command.

    azd down

    Theazd down command deletes the Azure resources and the GitHub Actions workflow.When prompted, agree to deleting all resources associated with the resource group.

    You may also delete theazdtest folder, or use it as the basis for your own application by modifying the files of the project.

Troubleshooting

If you see errors duringazd up, try the following steps:

  • Runazd down to remove any resources that may have been created. Alternatively, you can delete the resource group that was created in the Azure portal.
  • Delete theazdtest folder on your local computer.
  • In the Azure portal, search for Key Vaults. Select toManage deleted vaults, choose your subscription, select all key vaults that contain the nameazdtest or whatever you named your environment, and selectPurge.
  • Retry the steps in this quickstart again. This time when prompted, choose a simpler name for your environment. Try a short name, lower-case letters, no numbers, no upper-case letters, no special characters.
  • When retrying the quickstart steps, choose a different location.

See theFAQ for a more comprehensive list of possible issues and solutions.

Related Content


Feedback

Was this page helpful?

YesNo

In this article

Was this page helpful?

YesNo