简体   繁体   中英

Django-based Azure Web App getting stuck when development server is run (on Kudu)

To migrate an app from Heroku to Azure, I recently created a Django Azure Web App, connected it to my GitHub account and pushed my existing app code onto it via git push azure master . After some hiccups, I got all required packages to install correctly too (hiccups being installation of packages which required pythonwheels ).

I have NOT yet run syncdb on the app (the DB's to be hosted on a separate VM; it's postgresql). But I did try to run env\\scripts\\python manage.py runserver to see whether the development server would go up. It doesn't; Kudu gets stuck (shown below). 在此处输入图片说明

How can I get it to run? My web.config file is as follows:

<configuration>
  <appSettings>
    <add key="pythonpath" value="%SystemDrive%\home\site\wwwroot" />
    <add key="WSGI_HANDLER" value="hostingstart-python.application" />
    <add key="DJANGO_SETTINGS_MODULE" value="unconnectedreddit.settings" />
  </appSettings>
</configuration>

My project is called unconnectedreddit and it's placed inside wwwroot. The files manage.py , Procfile and web.config are placed at this level too. Procfile is a Heroku legacy; it contains code regarding what process to run on Heroku, eg: web: newrelic-admin run-program waitress-serve --port=$PORT unconnectedreddit.wsgi:application

The folder unconnectedreddit (see attached image) contains the settings.py and wsgi.py files. It also contains a folder called template , and a folder called static .

The app files are inside the links folder (ie models.py , views.py , forms.py ).

All packages are installed in env/Lib/site-packages/ .

Can someone explain what my setup lacks and how I can rectify it? Perhaps it's the mis-configured web.config, perhaps I need the Azure equivalent of Heroku's Procfile (though is that really necessary for a development server?), or perhaps it's something else.

I'll share more information if you feel you need it.

You won't be able to run the development server since it needs to bind to a socket. The only accessible ports are 80 and 443, however, Azure App Service itself is already bound to those. I suggest configuring your app with wfastcgi. See this example for details: https://github.com/theadriangreen/sample-azure-website-django-app

(Note: this is the same as gallery item for Django)

Running a Django app as an Web App should be fine. Documentation suggests setting up a virtualenv for the app, see https://azure.microsoft.com/en-us/documentation/articles/web-sites-python-create-deploy-django-app/#web-app-development---maclinux---command-line

Web.config is unnecessary unless you need to use HttpPlatformHandler . If you have initiation needs see http://www.iis.net/learn/extensions/httpplatformhandler/httpplatformhandler-configuration-reference .

Each Web App is assigned a port number that is bound the HTTP_PLATFORM_PORT environment variable. App Service will terminate incoming requests and forward them to the specified port. If Web App for some reason doesn't run the Django app you can explicitly tell HttpPlatformHandler how to execute the app, eg by writing a batch-file that runs python manage.py runserver 0.0.0.0:%HTTP_PLATFORM_PORT% and have HttpPlatformHandler execute the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM