我目前在Microsoft Azure上使用标准网站来托管web.py网站。如何在Microsoft Azure上使用web.py提供静态内容?
在web.py惯例是创建一个名为/static
举办静态文件,如图像,CSS和JavaScript目录。在我的本地环境中,这工作得很好。
但是,当我部署到Microsoft Azure时,我的静态内容将返回错误404。当我通过FTP查看目录时,可以看到文件均为,并且都是正确的。
我有一种感觉,这是值得做的事实,我的本地安装不需要使用WSGI的,但是托管在IIS在Azure上做。
我在Microsoft Azure python文档中发现,您可以使用web.config文件来提供静态内容,而无需使用web.py服务器,这将更快并可能解决此问题,但不会似乎已经解决了这个问题。
任何和所有帮助,将不胜感激。下面你可以看到我的webapp.py和web.config文件。
webapp.py
import web
render = web.template.render('templates/')
urls = (
'/', 'index',
'/feed', 'feed'
)
app = web.application(urls, globals(), autoreload=False)
class index:
def GET(self):
return render.index()
class feed:
def GET(self):
return 'The RSS feed of all the blogs on CS Blogs will appear here'
# If this file is being ran as the main program, start the web app.
if __name__ == "__main__":
app.run()
# This function allows azure to hook up the correct URLs to the correct functions
def wsgiHandler():
return web.application(urls, globals(), autoreload=False).wsgifunc()
的web.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="WSGI_HANDLER" value="webapp.wsgiHandler()" />
<add key="PYTHONPATH" value="D:\home\site\wwwroot" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="Python273_via_FastCGI" />
<remove name="Python340_via_FastCGI" />
<add name="Python FastCGI"
path="handler.fcgi"
verb="*"
modules="FastCgiModule"
scriptProcessor="D:\Python27\python.exe|D:\Python27\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>
</conditions>
<action type="Rewrite"
url="handler.fcgi/{R:1}"
appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>