-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathweb_server_cherrypy_css.py
More file actions
35 lines (28 loc) · 910 Bytes
/
Copy pathweb_server_cherrypy_css.py
File metadata and controls
35 lines (28 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
import cherrypy
import random
# Serve static files out of the web subdirectory
PATH = os.path.abspath(os.path.dirname(__file__)) + "/web"
class WebServer(object):
@cherrypy.expose
def index(self):
# Set the media type
cherrypy.response.headers['Content-Type'] = 'text/html'
random_number = random.randrange(1, 101)
result = "<html>"
result += "<head>"
result += "<link rel='stylesheet' type='text/css' href='style.css'>"
result += "</head>"
result += "<body>"
result += "<h1>My Page</h1>"
result += f"<p>My random number: {random_number}</p>"
result += "</body>"
result += "</html>"
return result
config = {
'/': {
'tools.staticdir.on': True,
'tools.staticdir.dir': PATH,
},
}
cherrypy.quickstart(WebServer(), config=config)