Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: wsgi with separate css file

Reply
Thread Tools

Re: wsgi with separate css file

 
 
Rami Chowdhury
Guest
Posts: n/a
 
      11-13-2009
On Fri, 13 Nov 2009 08:55:33 -0800, Alena Bacova <>
wrote:

> Hi,
> I'm using:
>
> from wsgiref import simple_server
> httpd = simple_server.make_server(HOST, PORT, Test)
> try:
> httpd.serve_forever()
> except KeyboardInterrupt:
> pass
>
> But I can use something else if needed. Application and htmk, css and
> images are stored on the same machine, everything is stored in one
> folder.
>
> Alena.
>


If you are just using this to learn to develop WSGI applications, I would
recommend implementing a method to distinguish requests for static files,
and handle them separately. A very naive implementation handling .css
files might look like:

from wsgiref import util
import os

def do_get(environ, start_response):
REQUEST_URI = util.request_uri(environ)
if (REQUEST_URI.endswith('.css')):
return do_css(REQUEST_URI, start_response)

# your regular code here

def do_css(request_uri, start_response):
full_path = os.path.abspath(os.path.join(MY_HTTP_DIRECTORY, request_uri))
if os.path.exists(full_path):
file_obj = open(full_path, 'r')
response_lines = file_obj.readlines()
file_obj.close()
start_response('200 OK', [('Content-Type', 'text/css')])
return response_lines
else:
start_response('404 Not Found', [])
return []

However, this method is fragile and very inefficient. If you want to
eventually deploy this application somewhere, I would suggest starting
with a different method.

Hope that helps,
Rami

--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --
Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
 
Reply With Quote
 
 
 
 
Aaron Watters
Guest
Posts: n/a
 
      11-13-2009

RE: serving static CSS files using WSGI

> ...However, this method is fragile and very inefficient. If you want to *
> eventually deploy this application somewhere, I would suggest starting *
> with a different method.


The WHIFF WSGI tools are meant to make this kind of thing easy.
In fact the quick start tells you how to do this

http://aaron.oirt.rutgers.edu/myapp/...500.quickstart

And if you want to deploy to the Google App Engine there's a
tutorial for that too:

http://aaron.oirt.rutgers.edu/myapp/...2300.GAEDeploy

For example the http://listtree.appspot.com/ service is implemented
using WHIFF under the Google App Engine environment.

-- Aaron Watters

===
TO INFINITY... AND BEYOND!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to edit .wsgi file extebtions with IDLE on windows gert Python 8 09-07-2009 11:11 PM
Separate Tabs, Separate Sessions BigAndy Firefox 0 05-09-2007 09:27 AM
Separate Tabs, Separate Sessions BigAndy Firefox 0 05-09-2007 09:26 AM
Using separate classpaths for separate classes? Frank Fredstone Java 1 06-27-2006 06:46 AM
How to use several separate classes (separate files) to be executed in one class (another file) EvgueniB Java 1 12-15-2003 01:18 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57