Skip to content

Instantly share code, notes, and snippets.

@nickstenning
Created March 16, 2017 09:07
Show Gist options
  • Save nickstenning/cb39d75bbc73badb968086653cefcf90 to your computer and use it in GitHub Desktop.
Save nickstenning/cb39d75bbc73badb968086653cefcf90 to your computer and use it in GitHub Desktop.
from flask import Flask
from flask import make_response, render_template
app = Flask(__name__)
@app.route('/')
def index():
resp = make_response(render_template('index.html'))
resp.headers['Content-Security-Policy'] = ("default-src 'none'; "
"font-src 'self'; "
"style-src 'self'; "
"script-src 'self'; ")
return resp
<!doctype html>
<link rel='stylesheet' href='{{ url_for('static', filename='main.css') }}'></script>
<p class='set-from-script'>
Once upon a midnight dreary, while I pondered, weak and weary. Over many a
quaint and curious volume of forgotten lore. While I nodded, nearly napping,
suddenly there came a tapping. As of some one gently rapping, rapping at my
chamber door. 'Tis some visiter, I muttered, tapping at my chamber door. Only
this, and nothing more. Ah, distinctly I remember it was in the bleak December.
And each separate dying ember wrought its ghost upon the floor. Eagerly I wished
the morrow;—vainly I had sought to borrow. From my books surcease of
sorrow—sorrow for the lost Lenore. For the rare and radiant maiden whom the
angels name Lenore. Nameless here for evermore. And the silken sad uncertain
rustling of each purple curtain Thrilled me, filled me with fantastic terrors
</p>
<p style='background-color: green'>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula
eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient
montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque
eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo,
fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut,
imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium.
Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate
eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac,
enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus
viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam
</p>
<script src='{{ url_for('static', filename='main.js') }}'></script>
p {
background-color: red;
}
document.querySelector('.set-from-script').style.backgroundColor = 'green';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment