Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

need some help in serving static files inside a wsgi apps

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


kibleur.christophe at gmail

May 24, 2008, 6:28 AM

Post #1 of 11 (257 views)
Permalink
need some help in serving static files inside a wsgi apps

Hi,

Until now, I was running my own static site with Python, but I'm in
need of dynamism.

After reading some cgi tutorials, I saw Joe Gregorio's old article
"Why so many Python web frameworks?" about wsgi apps [http://
bitworking.org/news/Why_so_many_Python_web_frameworks] and have a
question about it. The code he gave works like a charm (I had to make
a little change because SQLAlchemy has changed since), but how the
hell can I serve static files (css, js, images, etc.) within an wsgi
app, ie inside a '/static' directory ?!

Sorry if my question is a stupid one, but I cannot find an easy way to
do this. Each tutorial I'm reading out there does not talk about them
at all. All of my python books didn't mention wsgi either.

I know I could use web.py, web2py, Cherrypy, Django, Pylons, etc. but
I'm trying to understand basics of web dev. from their roots.

thanks in advance for any advice ,

Kib.
--
http://mail.python.org/mailman/listinfo/python-list


deets at nospam

May 24, 2008, 7:20 AM

Post #2 of 11 (236 views)
Permalink
Re: need some help in serving static files inside a wsgi apps [In reply to]

Tool69 schrieb:
> Hi,
>
> Until now, I was running my own static site with Python, but I'm in
> need of dynamism.
>
> After reading some cgi tutorials, I saw Joe Gregorio's old article
> "Why so many Python web frameworks?" about wsgi apps [http://
> bitworking.org/news/Why_so_many_Python_web_frameworks] and have a
> question about it. The code he gave works like a charm (I had to make
> a little change because SQLAlchemy has changed since), but how the
> hell can I serve static files (css, js, images, etc.) within an wsgi
> app, ie inside a '/static' directory ?!

There is a wsgi-app out there that is called "static". Use that.

And it's the first hit on google "wsgi static"... :)

http://lukearno.com/projects/static/

Diez
--
http://mail.python.org/mailman/listinfo/python-list


kib2 at free

May 24, 2008, 7:41 AM

Post #3 of 11 (240 views)
Permalink
Re: need some help in serving static files inside a wsgi apps [In reply to]

Diez B. Roggisch a écrit :
> Tool69 schrieb:
>> Hi,
>>
>> Until now, I was running my own static site with Python, but I'm in
>> need of dynamism.
>>
>> After reading some cgi tutorials, I saw Joe Gregorio's old article
>> "Why so many Python web frameworks?" about wsgi apps [http://
>> bitworking.org/news/Why_so_many_Python_web_frameworks] and have a
>> question about it. The code he gave works like a charm (I had to make
>> a little change because SQLAlchemy has changed since), but how the
>> hell can I serve static files (css, js, images, etc.) within an wsgi
>> app, ie inside a '/static' directory ?!
>
> There is a wsgi-app out there that is called "static". Use that.
>
> And it's the first hit on google "wsgi static"... :)
>
> http://lukearno.com/projects/static/
>
> Diez

Hi Diez,

and thanks for yout help. In fact I already found it but never managed
to get it work because the static doc says :

from wsgiref.simple_server import make_server
import static
make_server('localhost', 9999, static.Cling('/var/www')).serve_forever()

and inside J.Gregorio's tutorial it is:

from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
httpd = WSGIServer(('localhost', 8080), WSGIRequestHandler)
httpd.set_app(urls.urls)

It does not use 'make_server()' so how can I adapt it ?

I finally managed to work with static files with a little hack, but it's
ugly because I'm reading each static file per request.

Kib.
--
http://mail.python.org/mailman/listinfo/python-list


deets at nospam

May 24, 2008, 10:19 AM

Post #4 of 11 (238 views)
Permalink
Re: need some help in serving static files inside a wsgi apps [In reply to]

kib schrieb:
> Diez B. Roggisch a écrit :
>> Tool69 schrieb:
>>> Hi,
>>>
>>> Until now, I was running my own static site with Python, but I'm in
>>> need of dynamism.
>>>
>>> After reading some cgi tutorials, I saw Joe Gregorio's old article
>>> "Why so many Python web frameworks?" about wsgi apps [http://
>>> bitworking.org/news/Why_so_many_Python_web_frameworks] and have a
>>> question about it. The code he gave works like a charm (I had to make
>>> a little change because SQLAlchemy has changed since), but how the
>>> hell can I serve static files (css, js, images, etc.) within an wsgi
>>> app, ie inside a '/static' directory ?!
>>
>> There is a wsgi-app out there that is called "static". Use that.
>>
>> And it's the first hit on google "wsgi static"... :)
>>
>> http://lukearno.com/projects/static/
>>
>> Diez
>
> Hi Diez,
>
> and thanks for yout help. In fact I already found it but never managed
> to get it work because the static doc says :
>
> from wsgiref.simple_server import make_server
> import static
> make_server('localhost', 9999, static.Cling('/var/www')).serve_forever()
>
> and inside J.Gregorio's tutorial it is:
>
> from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
> httpd = WSGIServer(('localhost', 8080), WSGIRequestHandler)
> httpd.set_app(urls.urls)
>
> It does not use 'make_server()' so how can I adapt it ?

static.Cling is a wsgi-app. The other code just makes a specific
wsgi-implementation based server out of it.


> I finally managed to work with static files with a little hack, but it's
> ugly because I'm reading each static file per request.

How else should that work? Apache does that the same way.

Diez
--
http://mail.python.org/mailman/listinfo/python-list


basti.wiesner at gmx

May 24, 2008, 12:23 PM

Post #5 of 11 (236 views)
Permalink
Re: need some help in serving static files inside a wsgi apps [In reply to]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[ Diez B. Roggisch <deets [at] nospam> ]
>> I finally managed to work with static files with a little hack, but it's
>> ugly because I'm reading each static file per request.
>
> How else should that work? Apache does that the same way.

I guess, Apache does some kind of memory caching for files, which are often
requested and small enough to fit into the system memory. May be, that's
what the OP is referring to ...

- --
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkg4a1QACgkQn3IEGILecb5ibACgoYyLaOc+q51D0g+SuudnqHab
dYYAnjH3E0/e2y0owJ1PuWMk13i9YVA/
=7C8x
-----END PGP SIGNATURE-----
--
http://mail.python.org/mailman/listinfo/python-list


martin at v

May 25, 2008, 1:07 AM

Post #6 of 11 (222 views)
Permalink
Re: need some help in serving static files inside a wsgi apps [In reply to]

> I guess, Apache does some kind of memory caching for files, which are often
> requested and small enough to fit into the system memory.

Are you sure about this? I could not find anything in the documentation
(other than mod_cache and friends, which is an unrelated functionality).
Also, I don't see the need for Apache to cache frequently requested
files itself. Instead, the operating system will cache frequently
requested directories and files in memory, and it will do the same for
a Python web server.

Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


basti.wiesner at gmx

May 25, 2008, 2:04 AM

Post #7 of 11 (222 views)
Permalink
Re: need some help in serving static files inside a wsgi apps [In reply to]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[ "Martin v. Löwis" <martin [at] v> ]

>> I guess, Apache does some kind of memory caching for files, which are
>> often requested and small enough to fit into the system memory.
>
> Are you sure about this?

No, I'm not. That's why I said "I guess" ;)

> Also, I don't see the need for Apache to cache frequently requested
> files itself. Instead, the operating system will cache frequently
> requested directories and files in memory, and it will do the same for
> a Python web server.

Of course, a modern OS kernel will perform caching anyway, but this is most
likely slower than in-process caching, since it will still require context
switches from userspace into kernel space.

Considering this, it seems reasonable to me, that apache does memory
caching, but I'm by far not sure, I wouldn't put a bet on this ;)

- --
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkg5K7kACgkQn3IEGILecb48VwCeJYqoyi7IJKwASza9/u381dmg
PqMAn1M/JBe8xEsOAPNosNWA9WoKCvNh
=K3tE
-----END PGP SIGNATURE-----
--
http://mail.python.org/mailman/listinfo/python-list


deets at nospam

May 25, 2008, 4:42 AM

Post #8 of 11 (217 views)
Permalink
Re: need some help in serving static files inside a wsgi apps [In reply to]

Sebastian 'lunar' Wiesner schrieb:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> [ Diez B. Roggisch <deets [at] nospam> ]
>>> I finally managed to work with static files with a little hack, but it's
>>> ugly because I'm reading each static file per request.
>> How else should that work? Apache does that the same way.
>
> I guess, Apache does some kind of memory caching for files, which are often
> requested and small enough to fit into the system memory. May be, that's
> what the OP is referring to ...

I'm not aware of that, and I even more seriously doubt it. Because
caching is a complicated, domain-dependend subject that would
*immediately* cry for configuration - e.g. caching strategies and such.

And a common idiom for apache & caching is to use Squid as reverse
proxy. Which wouldn't be the case would apache cache by itself.

Diez
--
http://mail.python.org/mailman/listinfo/python-list


mattheww at chiark

May 25, 2008, 6:11 AM

Post #9 of 11 (217 views)
Permalink
Re: need some help in serving static files inside a wsgi apps [In reply to]

Diez B. Roggisch <deets [at] nospam> wrote:
>Sebastian 'lunar' Wiesner schrieb:
>> I guess, Apache does some kind of memory caching for files, which are often
>> requested and small enough to fit into the system memory. May be, that's
>> what the OP is referring to ...

> I'm not aware of that, and I even more seriously doubt it. Because
> caching is a complicated, domain-dependend subject that would
> *immediately* cry for configuration - e.g. caching strategies and such.

This is available in current apache with mod_file_cache (for an
explicitly configured list of files). I think the circumstances where
you'd want to use it are quite rare.

-M-
--
http://mail.python.org/mailman/listinfo/python-list


deets at nospam

May 25, 2008, 6:26 AM

Post #10 of 11 (215 views)
Permalink
Re: need some help in serving static files inside a wsgi apps [In reply to]

Matthew Woodcraft schrieb:
> Diez B. Roggisch <deets [at] nospam> wrote:
>> Sebastian 'lunar' Wiesner schrieb:
>>> I guess, Apache does some kind of memory caching for files, which are often
>>> requested and small enough to fit into the system memory. May be, that's
>>> what the OP is referring to ...
>
>> I'm not aware of that, and I even more seriously doubt it. Because
>> caching is a complicated, domain-dependend subject that would
>> *immediately* cry for configuration - e.g. caching strategies and such.
>
> This is available in current apache with mod_file_cache (for an
> explicitly configured list of files). I think the circumstances where
> you'd want to use it are quite rare.

As I said - explicit configuration is needed. And of course apache &
it's module system are flexible enough to allow caching as add-on. But
Sebastian speculated about some behind the scenes automatic caching.
Which apparently isn't there.

Diez
--
http://mail.python.org/mailman/listinfo/python-list


martin at v

May 25, 2008, 8:01 AM

Post #11 of 11 (215 views)
Permalink
Re: need some help in serving static files inside a wsgi apps [In reply to]

>>> I guess, Apache does some kind of memory caching for files, which are often
>>> requested and small enough to fit into the system memory. May be, that's
>>> what the OP is referring to ...
>
>> I'm not aware of that, and I even more seriously doubt it. Because
>> caching is a complicated, domain-dependend subject that would
>> *immediately* cry for configuration - e.g. caching strategies and such.
>
> This is available in current apache with mod_file_cache (for an
> explicitly configured list of files). I think the circumstances where
> you'd want to use it are quite rare.

Interestingly enough, this *doesn't* do memory caching for files.
Instead, it either keeps the file handle open, so you can seek to the
beginning of the file on the next request (avoiding the directory
lookup), or you can mmap the file. However, even if you mmap the file,
it is still the operating system's choice whether or not to cache the
file contents in memory.

Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.