Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Serving static files from a web.py + gevent server
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alexandre Rames  
View profile  
 More options Apr 13 2012, 5:57 pm
From: Alexandre Rames <alexandre.ra...@gmail.com>
Date: Fri, 13 Apr 2012 14:57:52 -0700 (PDT)
Local: Fri, Apr 13 2012 5:57 pm
Subject: Serving static files from a web.py + gevent server

Hello,

I am a beginner with webservers and gevent.

Using gevent with my web.py server prevents it from serving files located
in /static, which it normally does by default.
I hacked it by adding a   '/static/(.*)', 'static' path with a class
getting the correct files.
Is there a way to keep that automatic? Maybe a parameter when building the
WSGI server?

Thanks!

urls = (
  '/', 'index',
  '/static/(.*)', 'static'    # I don't want that
)
class index:
  def GET(self:
    # the rendered index includes    <script type="text/javascript" src="
/static/jquery.js <http://localhost:8080/static/jquery.js>"></script>
    return render.index()
class static:
  deg GET(self, name):
    return open('static/%s' % name)

if __name__ == "__main__":
  # That works without the additional static url and class.
  #web.application(urls,globals()).run()
  # That does not work without the 'static' additional code.
  application = web.application(urls, globals()).wsgifunc()
  print 'Serving on 8080...'
  WSGIServer(('localhost', 8080), application).serve_forever()


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jared McGuire  
View profile  
 More options Feb 22, 11:50 am
From: Jared McGuire <jrdm...@gmail.com>
Date: Fri, 22 Feb 2013 08:50:25 -0800 (PST)
Local: Fri, Feb 22 2013 11:50 am
Subject: Re: Serving static files from a web.py + gevent server

I'm also having this issue.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Butter  
View profile  
 More options Apr 15, 9:18 am
From: Eric Butter <emi...@ericbeurre.com>
Date: Mon, 15 Apr 2013 06:18:09 -0700 (PDT)
Local: Mon, Apr 15 2013 9:18 am
Subject: Re: Serving static files from a web.py + gevent server

This should not be an issue for you in production since you will have a
real webserver deciding to serve static files before anything hits the
WSGI.  
*But if you want to hard-code the static path in development, another
alternative is to overload the WSGI function's StaticMiddleware<https://github.com/webpy/webpy/blob/master/web/httpserver.py#L261>
:

## warning, pseudocode
class NewStaticMiddleware:
    def __init__(self, your_wsgi_fn):
        self.app = your_wsgi_fn
    def __call__(environ, start_response):
        if static_path:
            environ["STATIC"] = new_static_path
            web.httpserver.StaticApp(environ, start_response)  # static
files
        else:
            self.app(environ, start_response)  # reg wsgi resp

app = web.application(urls, globals())
your_wsgi = app.wsgi_func()
your_wsgi.StaticMiddleware = NewStaticMiddleware
## continue as normal


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »