Python Extensionless URLs with out mod_rewrite
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.
upd开发者_Go百科ate: 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.
WSGI doesn't use/need extensions at all; your routing framework handles the URL appropriately. And if you aren't using WSGI... why not?
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:
- 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)
- 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...
精彩评论