python - CherryPy can't seem to find CSS script (static or absolute paths) -


i'm using cherrypy framework serve site, cannot seem find css script either static path or absolute path. css script works fine if go index.tmpl file via browser, when request via cherrypy not use css script.

root directory structure:

site.py template/index.tmpl static/css/main.css 

site.py

import sys import cherrypy import os cheetah.template import template  class root:     @cherrypy.expose     def index(self):         htmltemplate = template(file='templates/index.tmpl')         htmltemplate.css_scripts=['css/main.css']         return str(htmltemplate)    # on startup current_dir = os.path.dirname(os.path.abspath(__file__)) + os.path.sep  cherrypy.config.update({     'environment': 'production',     'log.screen': true,     'server.socket_host': '127.0.0.1',     'server.socket_port': 2000,     'engine.autoreload_on': true,     '/':{         'tools.staticdir.root' : current_dir,         },     '/static':{         'tools.staticdir.on' : true,         'tools.staticdir.dir' : "static",     }, })  cherrypy.quickstart(root()) 

template/index.tmpl

<!doctype html> <html> <head>     #for $script in $css_scripts:         <link rel="stylesheet" href="$script" type="text/css" />     #end         <link rel="stylesheet" href="c:/absolute/path/main.css" type="text/css" /> </head> <body>         <! html code here> </body> </html> 

what doing wrong?

edit
have tried static/css/main.css static path
have tried relative paths, relative site.py , relative index.tmpl

error get:

get http://localhost:2000/static/css/main.css 404 (not found)   

i'm not sure why works, after trying million things fixed it. if knows why please enlighten me.

  • i changed config dictionary have global variables under sub-dictionary.
  • i got rid of cherrypy.config.update() function , fed config directly cherrypy.quickstart()

here changed code:

import sys import cherrypy import os cheetah.template import template  class root:     @cherrypy.expose     def index(self):         htmltemplate = template(file='templates/index.tmpl')         htmltemplate.css_scripts=['static/css/main.css']         return str(htmltemplate)  # on startup current_dir = os.path.dirname(os.path.abspath(__file__)) + os.path.sep config = {     'global': {         'environment': 'production',         'log.screen': true,         'server.socket_host': '127.0.0.1',         'server.socket_port': 2000,         'engine.autoreload_on': true,         'log.error_file': os.path.join(current_dir, 'errors.log'),         'log.access_file': os.path.join(current_dir, 'access.log'),     },     '/':{         'tools.staticdir.root' : current_dir,     },     '/static':{         'tools.staticdir.on' : true,         'tools.staticdir.dir' : 'static',     }, } cherrypy.quickstart(root(), '/', config) 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -