使用 WSGI 和 Python 3 提供静态文件
使用 WSGI 和 Python 3.2 提供静态文件的最简单方法是什么?有一些用于 PEP 333 和 Python 2 的 WSGI 应用程序用于此目的 - 但是关于 PEP 3333 和 Python 3 的吗?我想使用 wsgiref 进行开发。
What is the simplest way to serve static files with WSGI and Python 3.2? There are some WSGI apps for PEP 333 and Python 2 for this purpose - but was is about PEP 3333 and Python 3? I want to use wsgiref for development.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通常,您不希望使用 WSGI 提供静态文件。使用 WSGI 以便可以使用 Python 生成动态内容。根据定义,静态文件不是动态内容,因此您不需要额外的 WSGI 层以及您在其上构建的任何 Web 应用程序。相反,您最好设置 Web 服务器(apache、nginx、iis 等)以与 WSGI 应用程序一起单独提供静态文件。
编辑:有趣的是,在您澄清问题后,我发现自己陷入了这个境地。这是我发现的一些你可能会欣赏的东西。这就是所谓的“静态”。
https://github.com/lukearno/static
Typically, you don't want to serve static files using WSGI. WSGI is used so that dynamic content can be generated by using Python. Static files, by definition, are not dynamic content, so you don't need the additional layer of WSGI and any web app you've built on it. Instead, you would be best to set up your web server (apache, nginx, iis, etc.) to serve the static files separately, alongside your WSGI application.
Edit: Interestingly, I JUST found myself in this spot after you clarified your issue. Here's something I found that you might appreciate. It's called "static".
https://github.com/lukearno/static
Bottle 支持 PEP 3333,提供静态文件并且非常小。它可能适合您。我同意 Mark Hildreth 的回答,但如果您需要静态服务进行开发并使用 Python 3,Bottle 是一个不错的选择。注:瓶子使用2to3。
Bottle supports PEP 3333, serving static files and is very small. It might fit the bill for you. I agree with Mark Hildreth's answer, but if you need static serving for development and to work with Python 3, Bottle is a good bet. Note: Bottle uses 2to3.
以下是有关 Python 3 的 WSGI 应用程序信息的几个链接
。自定义:https://bitbucket.org/mitsuhiko/wsgi3k /
modwsgi:http://code.google.com/p/modwsgi/wiki/SupportForPython3X
CherryPy:http://www.cherrypy.org/wiki/WSGI 特别是 WSGI 1.0 与 WSGI 1.0 WSGI 1.1 部分。
所有这些链接都来自此页面:
http://www.wsgi.org/wsgi/Python_3
在我看来,目前最成熟的是 CherryPy。我还确信 CherryPy 提供了一种简单的方法来提供静态文件。
Here are several links to information on WSGI apps for Python 3.
Custom: https://bitbucket.org/mitsuhiko/wsgi3k/
modwsgi: http://code.google.com/p/modwsgi/wiki/SupportForPython3X
CherryPy: http://www.cherrypy.org/wiki/WSGI specifically the WSGI 1.0 vs. WSGI 1.1 section.
All those links come from this page:
http://www.wsgi.org/wsgi/Python_3
It looks to me like the most mature one at this point is CherryPy. I am also sure that CherryPy provides an easy way to serve static files.