On 9 June 2010 13:38, Shady <[email protected]> wrote:
> I've started Python programming a several months ago and have since
> began a website completely driven by Python (to enhance my Python
> knowledge). My Python web pages were basically standards Python
> scripts you can write up in Notepad, but with the added HTML
> formatting.
>
> For example, a script of mine looks like this on my PC:
>
> length = range(1,20)
> for num in length:
>   print num*2
>
> But then I obviously adapt it to output correctly in a browser:
>
> print "Content-Type..."
> print
>
> print "<html>....<body>"
> length = range(1,20)
>
> for num in length:
>   print num*2,"<br />"
>
> print "</body></html>"
>
> I then place it in the cgi-bin and execute it. Works wonderfully. The
> thing is, Bluehost's speed has begun to degrade and their Python
> support is average at best. So I'm moving to a host with better
> support and with better alternatives to CGI. Now, I'm confused with
> how I'm going to get my Python pages working under mod_wsgi. Do I have
> to completely rewrite each script for it to work?

To a degree. WSGI is not CGI.

> Is it possible for
> my Python scripts in their current format to work under mod_wsgi?

Only if you wrote a CGI emulation layer on top and ensure
multithreading was never used. It is not worth the trouble doing this.
Better to change to using WSGI interface.

> I'm
> completely lost on how I'm going to create seperate pages too. I've
> Googled but found haven't found too much.
>
> I've gotten mod_wsgi to work on my PC and I've gotten this wsgi script
> to run (a modified hello world script):
>
> #!C:\Python26\python.exe
>
> def application(environ, start_response):
>    numbers = ""
>    for x in range(1,20):
>        numbers += str(x)+" - "
>    file = open("\header.html").read()
>
>    start_response('200 OK', [('Content-Type', 'text/html')])
>    return [ file, numbers ]
>
> print "Why won't you work?!"
>
> The thing is, it doesn't print the last line. I know I'm doing
> something wrong and I know my idea of what mod_wsgi is probably
> skewed. If anyone can shed some light on my issues I'd really
> appreciate it. I just want the added bonus of mod_wsgi while using the
> standard Python scripting format, but it doesn't seem as if that's
> possible...

That last line will only print out once when script initially loaded
and it would only print to Apache error logs and not be a part of the
response returned to the client.

I would suggest you read:

  http://www.wsgi.org/wsgi/Learn_WSGI

Also suggest that you have a look at one of the micro frameworks such
as flask. This will make your life a lot easier as provides a lot of
high level abstractions for you so you don't have to do as much work.
Read:

  http://flask.pocoo.org/

Flask is one of many WSGI capable web frameworks for writing Python
web applications.

Graham

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/modwsgi?hl=en.

Reply via email to