Python 如何在Microsoft Azure上使用web.py提供静态内容?

Python 如何在Microsoft Azure上使用web.py提供静态内容?,python,iis,azure,web.py,Python,Iis,Azure,Web.py,我目前正在使用Microsoft Azure上的标准网站来托管Web.py网站 在web.py中,惯例是创建一个名为/static的目录来承载静态文件,如图像、css和javascript。在我当地的环境中,这很好用 但是,当我部署到Microsoft Azure时,我的静态内容返回一个错误404。当我通过FTP查看目录时,我可以看到所有文件都存在并且正确无误 我有一种感觉,这与我的本地安装不需要使用wsgi有关,但是Azure上IIS上的主机需要使用wsgi 我在Microsoft Azure

我目前正在使用Microsoft Azure上的标准网站来托管Web.py网站

在web.py中,惯例是创建一个名为
/static
的目录来承载静态文件,如图像、css和javascript。在我当地的环境中,这很好用

但是,当我部署到Microsoft Azure时,我的静态内容返回一个错误404。当我通过FTP查看目录时,我可以看到所有文件都存在并且正确无误

我有一种感觉,这与我的本地安装不需要使用wsgi有关,但是Azure上IIS上的主机需要使用wsgi

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

您需要将mime类型添加到需要返回的“非标准”类型中

示例:对于ogg、m4a和pdf,您可以在web的根目录中添加以下config.xml。如果config.xml已存在,请在中合并该节。有关扩展及其mimetype的完整列表,请访问



希望这有帮助。在坦帕的希利

我也有同样的问题。尝试以下修改:

替换

  <remove name="Python273_via_FastCGI" />
  <remove name="Python340_via_FastCGI" />

以下几行:

  <remove name="Python27_via_FastCGI" />
  <remove name="Python34_via_FastCGI" />

希望这能解决您的问题。:)

  <remove name="Python27_via_FastCGI" />
  <remove name="Python34_via_FastCGI" />