1

Developed a Python Flask Web App and connected to Azure SQL Database. The code is running successfully in local.

But when deployed to Web App in azure (Linux based web app ) either i am getting default page or the "Application Error :If you are the application administrator, you can access the diagnostic resources."

Not sure where i am going wrong. ANy help is deeply appreciated.

Below is the code.

    import textwrap
import pyodbc
from flask import Flask, render_template, request

app = Flask(__name__)

# DataBase Connections

driver = '{ODBC Driver 17 for SQL Server}' 
server_name ='sample-web'
database_name ='sample-web'
server = '{server_name}.database.windows.net,1433'.format(server_name=server_name)
username = "ramazdemo"
password = "Password123"
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database_name+';UID='+username+';PWD='+ password)

# Code

@app.route('/', methods = ['GET','POST'])
def index():
    
    if request.method == 'POST':
        userdetails = request.form
        name = userdetails['name']
        email = userdetails['email']
        crsr: pyodbc.Cursor = cnxn.cursor()
        crsr.execute("""INSERT INTO users (Name,Email) VALUES(?,?)""",(name,email))
        crsr.commit()
        crsr.close()
        return 'success'
    return render_template('index.html')

if __name__ == '__main__':
   app.run(debug=True)

App Service in Azure

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Any help is deeply appreciated. T

Joseph Xu
  • 5,607
  • 2
  • 5
  • 15
Ramdas Metla
  • 133
  • 3
  • 10

1 Answers1

1

Troubleshooting

The best way to find the problem is to query the log.

  1. Check ODBC driver( or you can reinstall drivers follow my answer in below post).

    How to access ODBC Driver on Azure App service

  2. Redeploy your web app by another way. The reason is to rule out that the current tool has bugs or environmental factors that cause the release to fail unrecognized.

    Deploy your Flask app on Azure in 3 easy steps

Jason Pan
  • 15,263
  • 1
  • 14
  • 29