473,670 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Pyt hon_web_framewo rks] 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.
Jun 27 '08 #1
9 3236
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_Pyt hon_web_framewo rks] 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
Jun 27 '08 #2
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.or g/news/Why_so_many_Pyt hon_web_framewo rks] 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('lo calhost', 9999, static.Cling('/var/www')).serve_fo rever()

and inside J.Gregorio's tutorial it is:

from wsgiref.simple_ server import WSGIServer, WSGIRequestHand ler
httpd = WSGIServer(('lo calhost', 8080), WSGIRequestHand ler)
httpd.set_app(u rls.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
Jun 27 '08 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[ Diez B. Roggisch <de***@nospam.w eb.de]
>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)

iEYEARECAAYFAkg 4a1QACgkQn3IEGI Lecb5ibACgoYyLa Oc+q51D0g+Suudn qHab
dYYAnjH3E0/e2y0owJ1PuWMk13 i9YVA/
=7C8x
-----END PGP SIGNATURE-----
Jun 27 '08 #4
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
Jun 27 '08 #5
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[ "Martin v. Löwis" <ma****@v.loewi s.de]
>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)

iEYEARECAAYFAkg 5K7kACgkQn3IEGI Lecb48VwCeJYqoy i7IJKwASza9/u381dmg
PqMAn1M/JBe8xEsOAPNosNW A9WoKCvNh
=K3tE
-----END PGP SIGNATURE-----
Jun 27 '08 #6
Sebastian 'lunar' Wiesner schrieb:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[ Diez B. Roggisch <de***@nospam.w eb.de]
>>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
Jun 27 '08 #7
Diez B. Roggisch <de***@nospam.w eb.dewrote:
>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-
Jun 27 '08 #8
Matthew Woodcraft schrieb:
Diez B. Roggisch <de***@nospam.w eb.dewrote:
>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
Jun 27 '08 #9
>>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
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7602
by: Joshua McCulloch | last post by:
I have setup Apache 2.0.50 and JBoss 3.2.5 using mod_jk2. My application is defined to operate in the root context (http://servername/) by creating a WEB-INF/jboss-web.xml I am serving static files (with apache) from a directory off the file system, by setting the DirectoryRoot variable in httpd.conf. JBoss is working off a .WAR built from this directory. Is there any way to reference the unarchived files from Apache?
3
1705
by: SteveM | last post by:
This is probably an easy answer but since I am fairly new to C++ for some reason I can't see it :-( Any help would be appreciated :-) I have a class: class AClass { public:
3
3674
by: Prash | last post by:
IIS serving javascript files, gives me error 4/21/2006 6:48 AM Guys/Gals, I am using IIS as a server to serve the javascript files. But it is giving me the error as "Object doesn't support this property or Method". I have modified the plugin-cfg.xml, to discard the entries of js files. Also, i checked to insure that the .js extension is added to the IIS mime type list by adding a mime type for .js as IIS6 will not serve up
0
910
by: AVL | last post by:
Hi, I've a requirement in which I need to show a powerpointf file in a web page... How can I acheive this? How can we show word documents or powerpoint files in web pages in asp.net?
3
1434
by: 205210864 | last post by:
i have the following code in one module Sub CreateAfile Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.CreateTextFile("c:\testfile.txt", True) End Sub
15
6295
nomad
by: nomad | last post by:
Hi everyone: I need help Please I'm still learning Java... Here is part of my code where I'm having problems. Problem is at public static void main(String args) { The method main cannot be declared static; static methods can only be declared in a static or top level type.. Code: public static void main(String args) { Employee emp = new Employee();
1
1222
by: SoixanteNeuf | last post by:
Sorry If this has been asked 1000 times but in a bind..Need simple code using Visual Basic 2005 on how to open a SqlExpress MDF file..How to extract the data would help also..I can open an MDB file with VB5 and extract data no problem. Was told last night I had to do this in Visual Basic 2005 and would by usuing SqlServer Express.And done by monday..Done the Interface not do much of a learning curve,,but the database connection is stalling me....
0
1005
by: emansc | last post by:
salamu alikom all, i inserted checkbox in a datagrid by using template column but in the run time, when i try to check any row & then click on a delete button,this row didn't deleted. i tried to enter the debug mode to see what is the problem, i found that the value of "checked" property of the checkbox is always false although i checked it. foreach (DataGridItem DataGridItem in dg_displayMsgs.Items) { if...
4
4045
by: silverleaf | last post by:
I'm starting to learn how to use the Allegro library with C++ on my own. My compiler is MSVisual C++ 6.0. The book I am learning out of is "Game Programming All In One, Third Edition" by Jonathan S. Harbour. I've been able to get all of the programs so far to run correctly except for the first one after setting up the compiler to statically link. I've installed the SDK for Direct X properly and the compiler has no problems linking. Yet, I...
0
8814
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8592
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8661
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6213
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2800
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2042
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.