Deploy a simple VS2017 Django app for Azure error - server

I'm trying to build a Django web app using VS2017 Preview (including Python tools for Visual Studio) and deploy the resulting app to Azure (I'm currently in a 30 day trial period for Azure evaluation).

I did the following:

  • Start VS2017, create a new project with the "Django Web Project" template. This creates a Django web page with a bootstrap template - simple and everything works well locally.

  • In VS go to Connected Services => Publish, select Microsft Azure Support, create a new App App and an App Plan. The instances are being created successfully.

  • Click Publish to publish via VS WebDeploy. Everything looks good in the console and at the end he says Publish: 1 succeeded, 0 failed, 0 skipped

    .

This results in the default Azure Welcome-start-page hostingstart.html

instead of the Django page. As soon as I delete this html file, there will only be The page cannot be displayed because an internal server error has occurred.

. I've tried different things: going to portal.azure.com "Application Settings", setting the Python version from "Off" to "3.4" (I'd like 3.5 actually, which one of the MS tutorials uses, but anyone will do for now) - then only appears hostingstart-python.html

, not yet Django. I tried to add the default web.config file via "Add => New Item => Azure web.config (FastCGI)" in VS. I tried editing this web.config with different values WSGI_HANDLER

(for example django.core.handlers.wsgi.WSGIHandler()

) and DJANGO_SETTINGS_MODULE

(for example mydjangopage.settings

), I tried adding "wfastcgi" to the requirements. Txt, etc.Always just getting a server error.

I've been trying to do this for hours and I've read every possible deployment help page from Microsoft, their blogs, and the internet. All information seems outdated, lacks information, or simply does not work. At this point I am very disappointed and ready to give up. Isn't it that simple? Create a new project in VS, click Publish and should it work? (This is definitely not, I have restarted from scratch several times and tried so many things.)

+1


source to share


3 answers


I had the same problem. I solved it this way:

Create a Django web app via the azure portal:

  • Go to azure and click the "plus sign" in the upper left corner to add a resource
  • Hover over Internet & Mobile.
  • Click "Show All"
  • Enter "Django" in the search box
  • Select the one marked in the picture below and create a resource following the instructions

Deploying a newly created resource



  • Go to Visual Studio and start deployment
  • Instead of creating a new azure resource from VS, select the one you just created for deployment.

Wait a minute.

  • It will take about 3 minutes until you see the deployment. Before that, you will get a default screen that looks a little different than the one you already know.
  • After that, you should see the correct django page.
0


source


Currently publishing support in VS 2017 is in a transition period. In the next two updates, we want to bring it back to the system with one click (in which case you can publish Python apps from anywhere, not just inside VS), but there are a few manual steps at the moment.

(I will summarize the steps below, but the canonical documentation will be at https://aka.ms/PythonOnAppService - now this is a blog post with these steps and some of the backstories)

  • After creating a new site (either through the portal or through VS - publishing content is fine too), install one of the Python site extensions Installing a site extension through the Azure Portal

  • Set your file web.config

    to the correct path to the site extension set in the attribute scriptProcessor

    (something like D:\home\python361x64\python.exe

    - see description of each extension for actual paths - VS 2017 also includes element templates to help you customize them, so check out "Add new element for ideas") ...

  • Update the variables WSGI_HANDLER

    and as needed DJANGO_SETTINGS_MODULE

    (typical WSGI_HANDLER

    for a Django app myapp.wsgi.application

    if you have a file wsgi.py

    in your project)

  • Publish your site via VS.

  • Use the console to install your packages - eg.D:\home\python361x64\python.exe -m pip install -r requirements.txt



You may have to restart your site at this point if something is already running, but in general you can quickly publish it via VS without having to reinstall Python or any packages.

If you are deploying your site over ARM using a JSON template, you can also specify a site extension: (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'))]"
        ]
      },
    ...

      

0


source


  • Build a WebApp on Azure (don't enable python in app settings!)

    From the deploy option select local git repository

    : deployment option From properties

    copy the git url:enter image description here

  • Copy the virtualenv_proxy.py

    file from https://github.com/Azure-Samples/python-docs-hello-world to your folder.

  • Create a file runtime.txt

    and write python-3.4

    to it.
  • Create a web.3.4.config

    content file :
<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 parameters you need to change here is the value for DJANGO_SETTINGS_MODULE

, replace myModule

with your module name. All settings and paths should be the same if you have created a web application.

  1. Push everything to the git url you got at point 1, Azure will detect and configure Python 3.4

    and install all packages from requirements.txt

    . After that, everything should work. If not, connect to ftp and look at \LogFiles\wfastcgi.log

    for an error.
0


source







All Articles