Mobile app version of vmapp.org
Login or Join
Sarah324

: How to use Python as a server language from a PHP perspective I only know server side programming with PHP. To me, I write something into index.php and call http://localhost/index.php and see

@Sarah324

Posted in: #Php #Python

I only know server side programming with PHP. To me, I write something into index.php and call localhost/index.php and see the results of the PHP script. I have been using CakePHP and understand that there is something you can do with URL rewriting, but in my mind, there is this one to one relation between URLs and PHP files on the server.

Now I do a lot with Python, but just command line utilites. I'd like to use Python instead of PHP for my next project. So far, I was told about mod_python, that I have to use a framework like Pylons or Twisted or even Django to get any output at all. Others have said that I just have to print() a HTTP header and then the script would output like I am used with PHP.

I would like to write something that basically only takes a directory listing and makes it pretty, so that I can access a bunch of PDF files from a mobile browser. I know how to do this with PHP, I know how to create a Python script that would generate the HTML. I just do not know how to execute that script when I open localhost/pdfcentral/.
How would I have to configure my server? It runs on Ubuntu 10.04.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Sarah324

2 Comments

Sorted by latest first Latest Oldest Best

 

@Murphy175

mod_python is not being actively developed anymore. While Apache says that doesn't mean the project is dead -


Currently mod_python is not under active development. This does not mean that it is "dead" as some people have claimed. It smiply means that the code and the project are mature enough when very little is required to maintain it.


But, it is suggested that one should use mod_wsgi instead. That is if you want to build everything from scratch. Which I suggest, you shouldn't, unless you are using this as a learning exercise.

It would be better to use a web-framework to do the heavy lifting - handling routing, requests, and the likes

A comprehensive list of Python web-frameworks is available here, but here are some that are popular -


Django - It is considered the Python equivalent of Ruby on Rails, and is pretty heavy duty, so wouldn't be a good fit for what you need.
Flask - It is a microframework. That is, it is small, doesn't get in your way, and is ideal for smaller projects that don't require a lot of batteries included.
Pyramid - It is built by the same group of people who built Pylons, which is no defunct. It is somewhere in between Flask and Django - can be used as a replacement for either.
Bottle - This is another microframework, and is even more minimal than Flask. Is just one file and has no dependencies(if you use the built in templating engine) other than the standard library, so would be a nice fit for what you want.
Web.py - Once powered Reddit(which was rewritten with new tools after being acquired).
webapp2 - It is the standard framework for the Google App Engine(though you can use other frameworks there).


Of these, I would recommend Flask, as I've used it and have no complaints. It also has a lot of extensions that would make life a lot easier if you want more features in your site.

Also, you would need a template engine - to assemble your html. Jinja2, built by the same guys who make Flask, and is pretty widely used. But coming from php web development, you might find using Mako more natural, which is pretty popular too.

Here is a more comprehensive faq on Python Web development - Python FAQ: Webdev.

10% popularity Vote Up Vote Down


 

@Nimeshi995

I found the question a little confusing and If I'm right I assume that your main objective is to serve files to your mobile phone using pretty styling?

If that is true then you shouldn't need to go though so many loops to set something up.

Apache2 allows you to edit the main file listing directory so you can style it pretty much anyway you want.

There is also many available ready main themes online just search Google for Theme for Apache2 Directory Listing, making it responsive wouldn't be to hard either.

Here's some information how to change the default look of Apache's

And heres some ready made templates to check out, there's many more....

Repos Style

Recurser

Indices

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme