Trindaz
Trindaz

Reputation: 17849

What is a pythonic webserver equivalent to IIS and ASP?

For very simple, internal web-apps using ASP I was able to just switch IIS 'on' and then write some ASP scripts in the www directory that would start working immediately.

Is there an equivalent webserver app for Python scripts that I can run that will automatically start serving dynamic pages (python scripts) in a certain folder (with virtually no configuration)?

Solutions I've already found are either too limited (e.g. SimpleHTTPRequestHandler doesn't serve dynamic content) or require configuring the script that does the serving.

Upvotes: 0

Views: 630

Answers (4)

chauncey
chauncey

Reputation: 676

For development or just to play around, here's an example using the standard Python library that I have used to help friend who wanted to get a basic CGI server up and running. It will serve python scripts from cgi-bin and files from the root folder. I'm not near a Windows computer at the moment to make sure that this still works. This also assumes Python2.x. Python 3.x has this, it's just not named the same.

  • Make a directory on your harddrive with a cgi-bin folder in it (Ex. "C:\server\cgi-bin")
  • In a command window, navigate to "C:\server" directory
  • Type the following assuming you've installed python 2.7 in C:\Python27: "c:\python27\python.exe -m CGIHTTPServer" You should get a message like "Serving HTTP on 0.0.0.0 port 8000"

Linux is the same - "python -m CGIHTTPServer" in a directory with a cgi-bin/ in it.

Upvotes: 1

Eric Wilson
Eric Wilson

Reputation: 59355

My limited experience with Python web frameworks has taught me that most go to one extreme or the other: Django on one end is a full-stack MVC framework, that will do pretty much everything for you. On the other end, there are Flask, web.py, CherryPy, etc., which do much less, but stay out of your way.

CherryPy, for example, not only comes with no ORM, and doesn't require MVC, but it doesn't even have a templating engine. So unless you use it with something like Cheetah, you can't write what would look like .asp at all.

Upvotes: 0

bobince
bobince

Reputation: 536399

There's always CGI. Add a script mapping of .py to "C:\Python27\python.exe" -u "%s" then drop .py files in a folder and IIS will execute them.

I'd not generally recommend it for real work—in the longer term you would definitely want to write apps to WSGI, and then deploy them through any number of interfaces including CGI—but it can be handy for quick prototyping.

Upvotes: 4

John Giotta
John Giotta

Reputation: 16944

WSGI setups are fairly easy to get started, but in no anyway turn key. django MVC has a simple built in development server if you plan on using a more comprehensive framework.

Upvotes: 0

Related Questions