不带 mod_rewrite 的 Python 无扩展 URL
我目前正在将一个网站从 php 移植到 python。 php Web 应用程序正在使用无扩展名的 url,方法是使用
DefaultType application/x-httpd-php
Is there things like this that I can do for python?我已经通过 Google 进行了搜索,并尝试添加对 python 有意义的 mime 类型,但到目前为止还没有成功。如果可能的话,我更愿意这样做而不是使用 mod_rewrite 。
谢谢。
更新:我的服务器当前设置为使用 wsgi,但是如果我的 python 脚本没有扩展名,浏览器将下载它们,而不是由服务器解析。
I am currently porting over a website from php to python. The php web app is using extenionless urls by using
DefaultType application/x-httpd-php
Is there something like this that I can do for python? I have searched around through Google and tried adding mime types that would make sense for python but so far have not been successful. I would prefer to do it this way instead of using mod_rewrite if at all possible.
Thanks.
update: My server is currently set up to use wsgi however if my python scripts do not have an extension the browser will download them as oppose to being parsed by the server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WSGI 根本不使用/不需要扩展;您的路由框架会适当地处理 URL。如果您不使用 WSGI...为什么不呢?
WSGI doesn't use/need extensions at all; your routing framework handles the URL appropriately. And if you aren't using WSGI... why not?
我想完整的答案将永远需要,但在 apache 上运行 python 的最佳方法是通过 WSGI,所以我建议你开始在这里查看: http://code.google.com/p/modwsgi/
这基本上需要两件事:
如果你正在构建一个网站,那么你必须处理很多事情,所以使用MVC 框架和 Django 是 python 的自然选择,除非您需要 websockets 支持等精美的现代功能。
它附带了一个关于设置机器的很棒的教程(对于 wsgi:http:// /docs.djangoproject.com/en/dev/howto/deployment/modwsgi/)
好处是 Django(与大多数 MVC 一样)负责路由您的请求 - 因此您不仅实现了无扩展,而且实现了完整的类似 REST 的访问。
使用 MVC 框架,您基本上可以从面向页面的网站转移到真正的 Web 应用程序......支持!
从这个答案开始,你应该能够在 stackoverflow 和 serverfault 上找到这么多相关的问答......
I guess a full answer would take forever, but the best way to run python on apache is through WSGI, so I suggest your start looking here: http://code.google.com/p/modwsgi/
This will basically require 2 things:
If you are building a website there are just so many things you have to take care of that it makes sense to use an MVC framework, and Django is a natural choice for python UNLESS you need fancy modern features such as websockets support.
It comes with a great tutorial on setting up your machine (for wsgi: http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/)
What's good is that Django (as most MVCs) take care of routing your requests - so you not only achieve the extensionless, but a full REST-like access.
With an MVC framework you are basically moving from a page-oriented website to a real web application... brace!
Starting with this answer you should be able to find just so many related Q&As on stackoverflow and serverfault...