I\'ve been trying to create a Django web app using VS2017 Preview (which includes Python tools for Visual Studio), and deploy the resulting app to Azure (I\'m currently on the 3
Create a WebApp on Azure (Do not enable python in Application Settings !)
From deployment option select local git repository
:
From properties
copy the git url:
Copy virtualenv_proxy.py
file from https://github.com/Azure-Samples/python-docs-hello-world into your folder.
Create a file runtime.txt
and write python-3.4
into it.
Create a file web.3.4.config
with content :
<configuration>
<appSettings>
<add key="WSGI_ALT_VIRTUALENV_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
<add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS"
value="D:\home\site\wwwroot\env\Scripts\python.exe" />
<add key="pythonpath" value="%SystemDrive%\home\site\wwwroot" />
<add key="WSGI_HANDLER" value="virtualenv_proxy.get_venv_handler()" />
<add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
<add key="DJANGO_SETTINGS_MODULE" value="myModule.settings" />
</appSettings>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<add name="Python FastCGI" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\Python34\python.exe|D:\Python34\Scripts\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
</handlers>
<rewrite>
<rules>
<rule name="Static Files" stopProcessing="true">
<conditions>
<add input="true" pattern="false" />
</conditions>
</rule>
<rule name="Configure Python" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
The only settings you need to change here is the value for DJANGO_SETTINGS_MODULE
, replace myModule
with your module name. All the over settings and paths should be exactly the same if you created an Web App.
Python 3.4
and install all packages from requirements.txt
.
After that everything should work. If not, connect using ftp and look into \LogFiles\wfastcgi.log
for the error.I had the same problem. I solved it as follows:
Create a Django Web App via the azure portal:
Deploy on the newly created resource
Wait a moment.
Right now, publishing support in VS 2017 is in a bit of a transition period. In the next couple of updates we want to get it back to a one-click system (and in the process, make it possible to publish Python apps from anywhere, not just within VS), but for now there are a couple of manual steps.
(I'll summarize the steps below, but the canonical documentation will be at https://aka.ms/PythonOnAppService - right now it's a blog post with these steps and some of the backstory)
After creating your new site (either through the portal or through VS - publishing content is okay too), install one of the Python site extensions
Configure your web.config
file to have the correct path to the site extension you installed in the scriptProcessor
attribute (something like D:\home\python361x64\python.exe
- see the description of each extension for the actual paths - VS 2017 also includes item templates to help set these up, so look through Add New Item for ideas)
Update the WSGI_HANDLER
and DJANGO_SETTINGS_MODULE
variables as necessary (a typical value for WSGI_HANDLER
for a Django app is myapp.wsgi.application
, assuming you have a wsgi.py
file in your project)
Publish your site through VS.
Use the console to install your packages - e.g. D:\home\python361x64\python.exe -m pip install -r requirements.txt
You may need to restart your site at this point if things were already running, but in general you can now publish quickly through VS without having to reinstall Python or any packages.
If you are deploying your site through ARM with a JSON template, you can also specify the site extension there: (from here)
"resources": [
{
"apiVersion": "2015-08-01",
"name": "[parameters('siteName')]",
"type": "Microsoft.Web/sites",
...
"resources": [
{
"apiVersion": "2015-08-01",
"name": "python352x64",
"type": "siteextensions",
"properties": { },
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('siteName'))]"
]
},
...