python - Tornado - why does static files without StaticFileHandler donot work? -
i new tornado. trying link css file html template. using jinja2 tornado. due unknown reasons css file not loading up.
edit: have created custom render_template
function working fine.
directory structure:
app.py static css custom.css templates index.html
here request handler's class:
class index(requesthandler): def get(self): path = os.path.join('static/css/', 'custom.css') return self.write(render_template('index.html', path = path))
and here index.html
template:
<!doctype html> <html> <head> <link rel="stylesheet" type="text/css" href="{{path}}"/> </head> <body> <div> <div class="header"> asdasdasd </div> </div><!--wrapper--> </body> </html>
but browser returning 404-notfound
error css file correct url, http://localhost/static/css/custom.css
here guide on how link static files in tornado: http://tornado.readthedocs.org/en/latest/guide/running.html#static-files-and-aggressive-file-caching
important 'static_path' setting in settings dictionary:
settings = { "static_path": os.path.join(os.path.dirname(__file__), "static") }
now should able use it.
Comments
Post a Comment