Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

License

NotificationsYou must be signed in to change notification settings

Azure-Samples/msdocs-flask-postgresql-sample-app

Repository files navigation

page_typelanguagesproductsurlFragmentnamedescription
sample
azdeveloper
python
bicep
html
azure
azure-app-service
azure-database-postgresql
azure-virtual-network
msdocs-flask-postgresql-sample-app
Deploy a Python (Flask) web app with PostgreSQL in Azure
This is a Python web app using the Flask framework and the Azure Database for PostgreSQL relational database service.

This is a Python web app using the Flask framework and the Azure Database for PostgreSQL relational database service. The Flask app is hosted in a fully managed Azure App Service. This app is designed to be be run locally and then deployed to Azure. You can either deploy this project by following the tutorialDeploy a Python (Django or Flask) web app with PostgreSQL in Azure or by using theAzure Developer CLI (azd) according to the instructions below.

Requirements

Therequirements.txt has the following packages, all used by a typical data-driven Flask application:

PackageDescription
FlaskWeb application framework.
SQLAlchemyProvides a database abstraction layer to communicate with PostgreSQL.
Flask-SQLAlchemyAdds SQLAlchemy support to Flask application by simplifying using SQLAlchemy. Requires SQLAlchemy.
Flask-MigrateSQLAlchemy database migrations for Flask applications using Alembic. Allows functionality parity with Django version of this sample app.
pyscopg2PostgreSQL database adapter for Python.
python-dotenvRead key-value pairs from .env file and set them as environment variables. In this sample app, those variables describe how to connect to the database locally.

Flask'sdotenv support sets environment variables automatically from an.env file.
flask_wtfForm rendering, validation, and CSRF protection for Flask with WTForms. Uses CSRFProtect extension.

Run the sample

This project has adev container configuration, which makes it easier to develop apps locally, deploy them to Azure, and monitor them. The easiest way to run this sample application is inside a GitHub codespace. Follow these steps:

  1. Fork this repository to your account. For instructions, seeFork a repo.

  2. From the repository root of your fork, selectCode >Codespaces >+.

  3. In the codespace terminal, run the following commands:

    # Install requirementspython3 -m pip install -r requirements.txt# Create .env with environment variablescp .env.sample.devcontainer .env# Run database migrationspython3 -m flask db upgrade# Start the development serverpython3 -m flask run
  4. When you see the messageYour application running on port 8000 is available., clickOpen in Browser.

Quick deploy

This project is designed to work well with theAzure Developer CLI, which makes it easier to develop apps locally, deploy them to Azure, and monitor them.

🎥 Watch a deployment of the code in [this screencast](https://www.youtube.com/watch?v=JDlZ4TgPKYc).

Steps for deployment:

  1. Sign up for afree Azure account

  2. Install theAzure Dev CLI. (If you opened this repository in a Dev Container, it's already installed for you.)

  3. Initialize a newazd environment:

    azd init

    It will prompt you to provide a name (like "flask-app"), which will later be used in the name of the deployed resources.

  4. Provision and deploy all the resources:

    azd up

    It will prompt you to login, pick a subscription, and provide a location (like "eastus"). Then it will provision the resources in your account and deploy the latest code. If you get an error with deployment, changing the location (like to "centralus") can help, as there may be availability constraints for some of the resources.

  5. Whenazd has finished deploying, you'll see an endpoint URI in the command output. Visit that URI, and you should see the front page of the restaurant review app! 🎉 If you see an error, open the Azure Portal from the URL in the command output, navigate to the App Service, select Logstream, and check the logs for any errors.

    Screenshot of Flask restaurants website

  6. When you've made any changes to the app code, you can just run:

    azd deploy

Getting help

If you're working with this project and running into issues, please post inIssues.

About

No description or website provided.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors13


[8]ページ先頭

©2009-2025 Movatter.jp