GithubHelp home page GithubHelp logo

azure-samples / msdocs-flask-postgresql-sample-app Goto Github PK

View Code? Open in Web Editor NEW
41.0 16.0 492.0 131 KB

License: MIT License

Python 12.96% Mako 0.64% HTML 15.43% Dockerfile 0.32% Bicep 70.27% Shell 0.38%
azd-templates flask python postgres

msdocs-flask-postgresql-sample-app's Introduction

page_type languages products urlFragment name description
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.

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. 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 tutorial Deploy a Python (Django or Flask) web app with PostgreSQL in Azure or by using the Azure Developer CLI (azd) according to the instructions below.

Requirements

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

Package Description
Flask Web application framework.
SQLAlchemy Provides a database abstraction layer to communicate with PostgreSQL.
Flask-SQLAlchemy Adds SQLAlchemy support to Flask application by simplifying using SQLAlchemy. Requires SQLAlchemy.
Flask-Migrate SQLAlchemy database migrations for Flask applications using Alembic. Allows functionality parity with Django version of this sample app.
pyscopg2 PostgreSQL database adapter for Python.
python-dotenv Read 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's dotenv support sets environment variables automatically from an .env file.
flask_wtf Form rendering, validation, and CSRF protection for Flask with WTForms. Uses CSRFProtect extension.

Run the sample

This project has a dev 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, see Fork a repo.

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

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

    # Install requirements
    python3 -m pip install -r requirements.txt
    # Create .env with environment variables
    cp .env.sample.devcontainer .env
    # Run database migrations
    python3 -m flask db upgrade
    # Start the development server
    python3 -m flask run
  4. When you see the message Your application running on port 8000 is available., click Open in Browser.

Quick deploy

This project is designed to work well with the Azure 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 a free Azure account

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

  3. Initialize a new azd 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. When azd 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 in Issues.

msdocs-flask-postgresql-sample-app's People

Contributors

bobtabor-msft avatar cephalin avatar dependabot[bot] avatar diberry avatar ianychoi avatar jianingwang123 avatar microsoft-github-operations[bot] avatar microsoftopensource avatar pamelafox avatar tonybaloney avatar v-geberr avatar v-xuto avatar vmagelo avatar

Stargazers

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

Watchers

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

msdocs-flask-postgresql-sample-app's Issues

[Feature request] Add section on how to connect to and query the database once deployed to Azure

Hi Azure team ๐Ÿ‘‹

This issue/request pertains to the tutorial in the MS Learn documentation: Deploy a Python (Django or Flask) web app with PostgreSQL in Azure

First off, I just want to say that the resources in that documentation and in the example repo are awesome. I've found them super helpful in getting hands-on learning for Azure, deploying Python apps, and creating servers and databases - both for day to day work and personal projects.

The YouTube tutorials (here and here) by @pamelafox were particularly helpful too.

One important thing that's missing though - something that would be immensely helpful to follow on from this particular exercise - was guidance on how to connect to and query the databases once they're deployed to Azure (I know that it's mentioned briefly in one of Pamela's videos, but this showed how to use SQLTools to browse the database locally in Codespaces, rather than how to access the DB deployed to Azure from the tutorial.)

In short, it's super easy to set up the Azure resources and deploy the app, but feels impossible to connect to and query the data.

I tried to figure this out myself, but with no success.

I've tried to connect using multiple methods from the Connect page in the Azure portal, including Azure Data Studio, DBeaver, pgAdmin, pg_dump, and psql and all end up in a similar situation, with an inability to connect or an error message about the server name not being recognised.

I've also gone through several guides and pieces of documentation (including this, this, this, and this), but keep hitting the same dead ends. Usually ending somewhere like this:

Image
Image
Image

It seems like having private network access and needing to access via a private endpoint adds to the complexity:

Image

Maybe I'm being a massive idiot, completely missing something obvious, but I've exhausted all of the guides/docs/tutorials and can find and I'm 99.9% I completed the steps correctly, with absolute certainty that I was entering details (i.e. server names, IP addresses, credentials etc.) correctly and trying on both flexible and single servers too.

Perhaps this would warrant another new tutorial on the MS Learn docs, rather than an extra section on the existing tutorial.

But this would be very helpful as most of the value of having a database comes from being able to query it to glean insights from the data.

PS - FWIW, and if it helps at all, I'd be more than happy to help prepare the materials if I had an understanding on how to do it ๐Ÿ˜…

PPS - I work at GitHub, so you can reach out directly via the GH or MS emails or Slack if you want to chat!

azd up fails on provisiong step - seems to fail on postgres.

This template fails to run when azd up is executed.

Minimal steps to reproduce

azd init --template (name)
azd up

Any log messages given by the failure

"Deployment error details: ParameterOutOfRange: The value of the version should be in []. Verify that the specified paramter value is correct."

Expected/desired behavior

azd up completes and provisions/deploys app

OS and Version?

Windows 10

Versions

Mention any other details that might be useful

Used Eastus2 region, was running both locally and in cloudshell.


Thanks! We'll be in touch soon.

Updating/work-with this template for GHA feature.

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

We are updating this template to support new features in Github Action.

For the Github Action feature: We will remove two lines of code on container image and add GHA code after checkout step in the .github/workflow/azure-dev.yml file. (Shown as below)
image

@rajeshkamal5050 , @pamelafox for notification.

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.