zoukankan      html  css  js  c++  java
  • cherrypy 访问静态文件

    This is why /static/css/style.css is found in public/css/style.css

    code

    import os, os.path
    import random
    import string
    import cherrypy
    
    
    
    
    class StringGenerator(object):
        @cherrypy.expose
        def index(self):
            return """<html>
              <head>
                <link href="/static/css/style.css" rel="stylesheet">
              </head>
              <body>
                <form method="get" action="generate">
                  <input type="text" value="8" name="length" />
                  <button type="submit">Give it now!</button>
                </form>
              </body>
            </html>"""
    
    
        @cherrypy.expose
        def generate(self, length=8):
            some_string = ''.join(random.sample(string.hexdigits, int(length)))
            cherrypy.session['mystring'] = some_string
            return some_string
    
    
        @cherrypy.expose
        def display(self):
            return cherrypy.session['mystring']
    
    
    
    
    if __name__ == '__main__':
        conf = {
            '/': {
                'tools.sessions.on': True,
                'tools.staticdir.root': os.path.abspath(os.getcwd())
            },
            '/static': {
                'tools.staticdir.on': True,
                'tools.staticdir.dir': os.path.abspath(os.getcwd())+'/public'
            }
        }
        cherrypy.quickstart(StringGenerator(), '/', conf)

  • 相关阅读:
    关于struts页面跳转的问题
    java中==和equals的区别
    控制广播风暴的方法
    广播风暴的成因及解决办法
    思科FEX配置
    思科vPC技术和配置
    数据中心架构TOR和EOR
    ARP表项及老化时间
    MAC地址表和老化时间
    track 3 list boolean or
  • 原文地址:https://www.cnblogs.com/sea-stream/p/14179209.html
Copyright © 2011-2022 走看看