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, e.g.: 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 (i.e. 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.
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 useHttpPlatformHandler
. 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 tellHttpPlatformHandler
how to execute the app, e.g. by writing a batch-file that runspython manage.py runserver 0.0.0.0:%HTTP_PLATFORM_PORT%
and haveHttpPlatformHandler
execute the file.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)