Skip to content

Instantly share code, notes, and snippets.

@bmxp
Last active August 18, 2019 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bmxp/f0f4ebe52019d2d239ab0abe8f5e4867 to your computer and use it in GitHub Desktop.
Save bmxp/f0f4ebe52019d2d239ab0abe8f5e4867 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

import os, os.path
import random
import string
import cherrypy
class Demo(object):
@cherrypy.expose
def index(self):
return open('static\\index.html', encoding='utf-8')
@cherrypy.expose
def indexfail(self):
return open('static\\indexfail.html', encoding='utf-8')
if __name__ == '__main__':
conf = {
'/': {
'tools.sessions.on': True,
'tools.staticdir.root': os.path.abspath(os.getcwd())
},
'/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