Deploy a simple VS2017 Django app to Azure - server error

前端 未结 3 754
再見小時候
再見小時候 2021-01-27 03:53

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

相关标签:
3条回答
  • 2021-01-27 04:07
    1. 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:

    2. Copy virtualenv_proxy.py file from https://github.com/Azure-Samples/python-docs-hello-world into your folder.

    3. Create a file runtime.txt and write python-3.4 into it.

    4. 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.

    1. Push everything to the git url you got at point 1, Azure will detect and set up 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.
    0 讨论(0)
  • 2021-01-27 04:09

    I had the same problem. I solved it as follows:

    Create a Django Web App via the azure portal:

    1. Go to azure and hit the "plus sign" in the left upper corner for adding a resource
    2. Kick on “Web and Mobile”
    3. Click on “Show all”
    4. Type “Django” into the search field
    5. Select the one that is marked in the picture below and create the resource by following the instructions

    Deploy on the newly created resource

    1. Go to Visual Studio and start the deployment
    2. Instead of creating a new azure resource out of VS select the one you just created for the deployment.

    Wait a moment.

    1. It takes about 3 minutes until you can see you deployment. Before that you will get a default screen that looks a bit different than the one you already know.
    2. After that you should see the correct django page.
    0 讨论(0)
  • 2021-01-27 04:26

    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)

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

    2. 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)

    3. 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)

    4. Publish your site through VS.

    5. 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'))]"
            ]
          },
        ...
    
    0 讨论(0)
提交回复
热议问题