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()
On Friday, April 13, 2012 5:57:52 PM UTC-4, Alexandre Rames wrote:
> 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()
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> :
On Friday, February 22, 2013 11:50:25 AM UTC-5, Jared McGuire wrote:
> I'm also having this issue.
> On Friday, April 13, 2012 5:57:52 PM UTC-4, Alexandre Rames wrote:
>> 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()