不带 mod_rewrite 的 Python 无扩展 URL

发布于 2024-11-01 08:27:56 字数 362 浏览 8 评论 0原文

我目前正在将一个网站从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

转角预定愛 2024-11-08 08:27:56

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?

雨后彩虹 2024-11-08 08:27:56

我想完整的答案将永远需要,但在 apache 上运行 python 的最佳方法是通过 WSGI,所以我建议你开始在这里查看: http://code.google.com/p/modwsgi/

这基本上需要两件事:

  1. apache的mod_wsgi(小警告,从apt包安装将切换你的apache MPM并可能卸载你的 mod_php 确实可以共存,但是需要一些手工工作)
  2. 一个实现基本 wsgi 接口的 python 脚本

如果你正在构建一个网站,那么你必须处理很多事情,所以使用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:

  1. mod_wsgi for apache (little warning, installing from apt packages will switch your apache MPM and likely uninstall your mod_php; they do can live together, but some handwork is gonna be needed)
  2. a python script that implements basic wsgi interface

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文