如何使用网页.py在Microsoft Azure上?

2024-04-19 04:46:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我当前正在使用Microsoft Azure上的标准网站托管网页.py网站。在

在网页.py惯例是创建一个名为/static的目录来托管静态文件,如图像、css和javascript。在我当地的环境下,这个很好。在

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

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

我在microsoftazurepython文档中发现可以使用web.config文件文件来提供静态内容,而不必使用网页.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文件

^{pr2}$

Tags: 文件thepywebconfigapp网页index
2条回答

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

更换

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

有了这些线条:

^{pr2}$

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

您需要添加一个mime类型,即需要返回的“非标准”类型。在

示例:对于ogg、m4a和pdf,可以添加以下内容配置.xml在你的网络的根。如果配置.xml已存在合并分区。扩展及其mimetype的完整列表可以在http://www.feedforall.com/mime-types.htm找到。在

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
    <staticContent>
        <remove fileExtension=".m4a" />
        <mimeMap fileExtension=".m4a" mimeType="audio/mp4a-latm"/>
        <remove fileExtension=".ogg" />
        <mimeMap fileExtension=".ogg" mimeType="application/ogg"/>
        <remove fileExtension=".pdf" />
        <mimeMap fileExtension=".pdf" mimeType="application/pdf"/>
    </staticContent>
</system.webServer>
</configuration>

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

相关问题 更多 >