Skip to content

Instantly share code, notes, and snippets.

@webknjaz
Forked from bmxp/Demo.py
Last active August 18, 2019 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webknjaz/bf96eba1493a6d709b7e43ade70c043f to your computer and use it in GitHub Desktop.
Save webknjaz/bf96eba1493a6d709b7e43ade70c043f to your computer and use it in GitHub Desktop.
Doctype Bug

Directory structure:

DOCTYPEBUG
X:.
│   Demo.py
│
└───static
    │   index.html
    │   indexfail.html
    │
    └───css
            style.css

The only difference between index.html and indexfail.html is the first line. If is omitted then the background looks fine in green and we have a pleasing Hello world If it is included then css won't be used for display.

Tested with Cherrypy 18.1.2 on Windows

from pathlib import Path
import cherrypy
class Demo:
@cherrypy.expose
def index(self):
return Path('static/index.html').open(encoding='utf-8')
@cherrypy.expose
def indexfail(self):
return Path('static/indexfail.html').open(encoding='utf-8')
if __name__ == '__main__':
conf = {
'/': {
'tools.sessions.on': True,
'tools.staticdir.root': Path(__file__).parent.absolute(),
},
'/static': {
'tools.staticdir.on': True,
'tools.staticdir.dir': './static',
}
}
cherrypy.quickstart(Demo(), '/', conf)
<html lang="de">
<head>
<meta charset="utf-8">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Hello world</title>
<link href="/static/css/style.css" rel="stylesheet">
</head>
<body>
<h1>Hello world</h1>
</body>
</html>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Hello world</title>
<link href="/static/css/style.css" rel="stylesheet">
</head>
<body>
<h1>Hello world</h1>
</body>
</html>
/* put in directory static/css */
body {
background-color: green;
}
h1 {
font-family: sans-serif;
color: whitesmoke;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment