static file handling fix

This commit is contained in:
Nikolay Markov 2012-09-10 13:53:14 +04:00 committed by default
parent a02a9081f8
commit 71d3bd85cc
4 changed files with 24 additions and 4 deletions

View File

@ -36,6 +36,10 @@ if __name__ == "__main__":
runwsgi_parser = subparsers.add_parser(
'runwsgi', help='run WSGI application'
)
runwsgi_parser.add_argument(
'-p', '--port', dest='port', action='store', type=str,
help='application port', default='8000'
)
test_parser = subparsers.add_parser(
'test', help='run unit tests'
)
@ -86,7 +90,7 @@ if __name__ == "__main__":
else:
logging.info("Running WSGI app...")
server = web.httpserver.WSGIServer(
("0.0.0.0", 8080),
("0.0.0.0", int(params.port)),
app.wsgifunc()
)
try:

View File

@ -5,5 +5,5 @@ from webui.urls import webui_app
urls = (
"/api", api_app,
"/", webui_app
"", webui_app
)

View File

@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
import web
import mimetypes
import posixpath
from settings import settings
render = web.template.render(settings.TEMPLATE_DIR)
@ -9,3 +11,16 @@ render = web.template.render(settings.TEMPLATE_DIR)
class IndexHandler(object):
def GET(self):
return render.index()
class StaticHandler(object):
def GET(self, fl):
fl_path = posixpath.join(settings.STATIC_DIR, fl)
mimetype = mimetypes.guess_type(fl_path)[0]
if mimetype:
web.header("Content-Type", mimetype)
try:
f = open(fl_path, 'r')
return f.read()
except:
raise web.notfound()

View File

@ -2,10 +2,11 @@
import web
from webui.handlers import IndexHandler
from webui.handlers import IndexHandler, StaticHandler
urls = (
r"", 'IndexHandler',
r"/static/(.*)", 'StaticHandler',
r"/", 'IndexHandler',
)
webui_app = web.application(urls, locals())