目录结构
cherrypy 访问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': './public'
        }
    }
    cherrypy.quickstart(StringGenerator(), '/', conf)

 

 
 
 
 
 
 
 
 

相关文章:

  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
  • 2021-09-23
  • 2021-08-22
  • 2022-12-23
猜你喜欢
  • 2021-10-08
  • 2021-12-14
  • 2021-08-11
  • 2021-08-26
  • 2021-12-11
  • 2021-06-28
  • 2022-12-23
相关资源
相似解决方案