如何在 webpy 中提供文件?
我正在使用 webpy 框架。我想根据其中一个请求提供静态文件。 webpy 框架中有特殊的方法吗?还是我只需要读取并返回该文件?
I am using webpy framefork. I want to serve static file on one of requests. Is there special method in webpy framework or I just have to read and return that file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
其他答案对我不起作用。
您可以先在app.py中加载html文件,甚至可以在app.py中编写html。
然后,您可以使索引类的 GET 方法返回静态 html。
The other answers did not work for me.
You can first load the html file in app.py or even write the html within app.py.
Then, you can make the index class' GET method return the static html.
如果您正在运行开发服务器(没有 apache):
参考:http://webpy.org/cookbook/staticfiles
更新。如果您确实需要在
/
上提供静态文件,您可以简单地使用重定向:If you are running the dev server (without apache):
Reference: http://webpy.org/cookbook/staticfiles
Update. If you really need to serve a static file on
/
you can simply use a redirect:在过去的几个小时里我一直在努力解决这个问题……哎呀!
找到了两个都适合我的解决方案......
1 - 在 .htaccess 中,在 ModRewrite 行之前添加此行:
这将确保对 /static/ 目录的请求不会被重写以转到您的 code.py 脚本。
2 - 在 code.py 中为每个目录添加一个静态处理程序和一个 url 条目:
注意 - 我从 web.py 谷歌组偷了这个,但再也找不到那个该死的帖子了!
其中任何一个都对我有用,无论是在 web.py 模板中还是直接调用我放入“静态”的网页
I struggled with this for the last couple of hours... Yuck!
Found two solutions which are both working for me...
1 - in .htaccess add this line before the ModRewrite line:
This will make sure that requests to the /static/ directory are NOT rewritten to go to your code.py script.
2 - in the code.py add a static handler and a url entry for each of several directories:
Note - I stole this from the web.py google group but can't find the dang post any more!
Either of these worked for me, both within the templates for web.py and for a direct call to a web-page that I put into "static"
我不建议使用 web.py 提供静态文件。你最好为此配置 apache 或 nginx。
I don't recommend serving static files with web.py. You'd better have apache or nginx configured for that.