I am using visual studio to create a blank Flask app. When I run the application locally, I get the expected "hello world". When I publish to Azure App Service, I get this nice ugly blue home page that I didn't make. No where in my project does this code exist, atleast that I can see in visual studio solution explorer. If I try to nagivate to <my account name>.azurewebsites.net/test
I get a 404
error. Any suggestion?
app.py:
from flask import Flask
app = Flask(__name__)
# Make the WSGI interface available at the top level so wfastcgi can get it.
wsgi_app = app.wsgi_app
@app.route('/test')
@app.route('/')
def hello():
"""Renders a sample page."""
return "Hello World!"
if __name__ == '__main__':
import os
HOST = os.environ.get('SERVER_HOST', 'localhost')
try:
PORT = int(os.environ.get('SERVER_PORT', '5555'))
except ValueError:
PORT = 5555
app.run(HOST, PORT)
web deploy.pubxml:
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<ResourceId>/subscriptions/78439574-998e-4216-b54c-40fa45d65ca5/resourceGroups/Default-SQL-EastUS/providers/Microsoft.Web/sites/FlaskWebProject220180702122411</ResourceId>
<ResourceGroup>Default-SQL-EastUS</ResourceGroup>
<PublishProvider>AzureWebSite</PublishProvider>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>http://flaskwebproject220180702122411.azurewebsites.net</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<MSDeployServiceURL>flaskwebproject220180702122411.scm.azurewebsites.net:443</MSDeployServiceURL>
<DeployIisAppPath>FlaskWebProject220180702122411</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<EnableMSDeployBackup>True</EnableMSDeployBackup>
<UserName>$FlaskWebProject220180702122411</UserName>
<_SavePWD>True</_SavePWD>
<_DestinationType>AzureWebSite</_DestinationType>
</PropertyGroup>
</Project>
UPDATE:
I followed the steps listed by Jay. I am now getting a "The page cannot be displayed because an internal server error has occurred.". I added a log file in the application setting, however, it does not appear.
UPDAtE 2
I noticed that in my from web.config the versions were different so i updated it. this allowed the logs.txt to be created.
<add name="PythonHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\Python364x64\python.exe|D:\home\Python364x64\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>
I am still getting a 500 error.
Please refer to my work steps and see if the error still shows up.
Step 1 : Create azure web app and add Extensions(here is Python 3.6.1 x64)
Step 2 : Publish your
flask
project and add theweb.config
.web.config:
If you deploy successfully, you could see following structure in the
KUDU
path:D:\home\site\wwwroot>
.If you want to use additional python package, please go on.
Step 3: Switch to the Kudu CMD and commands
cd Python361x64
andtouch get-pip.py
and copy the content of the urlhttps://bootstrap.pypa.io/get-pip.py
into theget-pip.py
via Edit button, then runpython get-pip.py
to install the pip tool.Step 4 : Install any packages you need via
python -m pip install pyodbc
Hope it helps you. Any concern ,please let me know.
Update:
In my steps, copy content in
https://bootstrap.pypa.io/get-pip.py
to install pip. It could identify the system python version, install the corresponding python package.So,you just need to run the command
python -m pip install newspaper3k
to installnewspaper3k
.