我目前在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>