[英]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
. 要将应用程序从Heroku迁移到Azure,我最近创建了一个Django Azure Web App,将其连接到我的GitHub帐户,并通过
git push azure master
将现有的应用程序代码推送到了其中。 After some hiccups, I got all required packages to install correctly too (hiccups being installation of packages which required pythonwheels ). 打some之后,我也得到了所有必需的软件包,它们也都可以正确安装(打ic是需要pythonwheels的软件包的安装)。
I have NOT yet run syncdb
on the app (the DB's to be hosted on a separate VM; it's postgresql). 我尚未在应用程序上运行
syncdb
(数据库将托管在单独的VM上;它是PostgreSQL)。 But I did try to run env\\scripts\\python manage.py runserver
to see whether the development server would go up. 但是我确实尝试运行
env\\scripts\\python manage.py runserver
来查看开发服务器是否正常运行。 It doesn't; 不会的 Kudu gets stuck (shown below).
Kudu卡住(如下所示)。
How can I get it to run? 我如何才能运行它? My web.config file is as follows:
我的web.config文件如下:
<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. 我的项目称为
unconnectedreddit
,它放置在wwwroot中。 The files manage.py
, Procfile
and web.config
are placed at this level too. 文件
manage.py
, Procfile
和web.config
也位于此级别。 Procfile is a Heroku legacy; Procfile是Heroku的遗产; it contains code regarding what process to run on Heroku, eg:
web: newrelic-admin run-program waitress-serve --port=$PORT unconnectedreddit.wsgi:application
它包含有关在Heroku上运行哪个进程的代码,例如:
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. 文件夹
wsgi.py
(请参见附件)包含settings.py
和wsgi.py
文件。 It also contains a folder called template
, and a folder called static
. 它还包含一个名为
template
的文件夹和一个名为static
的文件夹。
The app files are inside the links
folder (ie models.py
, views.py
, forms.py
). 应用程序文件位于
links
文件夹内(即models.py
, views.py
, forms.py
)。
All packages are installed in env/Lib/site-packages/
. 所有软件包都安装在
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.
也许是配置错误的web.config,也许我需要与Azure等效的Heroku的Procfile(尽管对于开发服务器确实需要吗?),或者还有其他东西。
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.
唯一可访问的端口是80和443,但是Azure App Service本身已绑定到这些端口。 I suggest configuring your app with wfastcgi.
我建议使用wfastcgi配置您的应用程序。 See this example for details: https://github.com/theadriangreen/sample-azure-website-django-app
有关详细信息,请参见以下示例: https : //github.com/theadriangreen/sample-azure-website-django-app
(Note: this is the same as gallery item for Django) (注意:这与Django的图库项目相同)
Running a Django app as an Web App should be fine. 将Django应用程序作为Web应用程序运行应该很好。 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
文档建议为该应用程序设置virtualenv,请参阅https://azure.microsoft.com/zh-CN/documentation/articles/web-sites-python-create-deploy-django-app/#web-app-development- --maclinux ---命令行
Web.config
is unnecessary unless you need to use HttpPlatformHandler
. 除非您需要使用
HttpPlatformHandler
否则不需要Web.config
。 If you have initiation needs see http://www.iis.net/learn/extensions/httpplatformhandler/httpplatformhandler-configuration-reference . 如果您有启动需求,请参阅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. 每个Web应用程序都分配有一个端口号,该端口号绑定到
HTTP_PLATFORM_PORT
环境变量。 App Service will terminate incoming requests and forward them to the specified port. App Service将终止传入的请求,并将其转发到指定的端口。 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. 如果Web应用由于某种原因未运行Django应用,则可以明确告诉
HttpPlatformHandler
如何执行该应用,例如,编写运行python manage.py runserver 0.0.0.0:%HTTP_PLATFORM_PORT%
的批处理文件,并让HttpPlatformHandler
执行文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.