I don't know how make routings in cherrypy and how define css and js file in conf in index.py
I have a structure:
index.py
|
-views
|
-home
|
-index.html
-login.html
-public
|
-css
bootstrap.css
...
-js
-images
And when I start Cherrypy
server with index.html
in my site I have 404
in css
file and when I click button with href
to login.html
I can't go there, because I see 404
. Please a help because I am newbie in `Cherrypy.
import cherrypy
import webbrowser
import os, os.path
VIEWS_DIR = os.path.join(os.path.abspath("."), u"VIEWS")
CSS_DIR = os.path.join(os.path.abspath("."), u"CSS")
class Main(object):
@cherrypy.expose()
def index(self):
return open('views/home/index.html', 'rb').read().decode('utf-8')
conf = {
'/': {
'tools.sessions.on': True,
'tools.staticdir.root': os.path.abspath(os.getcwd()),
},
'/static/views/home':
{'tools.staticdir.on': True,
'tools.staticdir.dir': VIEWS_DIR,
},
'/bootstrap.css':
{ 'tools.staticfile.on':True,
'tools.staticfile.filename': os.path.abspath ("./public/css/bootstrap.css"),
},
}
def open_page():
webbrowser.open("http://127.0.1.1:8080/")
cherrypy.engine.subscribe('start', open_page)
cherrypy.tree.mount(Main(), '/', conf)
cherrypy.engine.start()
404 error
in css
file and when I click to href
link in site index.html