Skip to content

Instantly share code, notes, and snippets.

@andytwoods
Created September 18, 2020 13:49
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 andytwoods/8cd21ea6d09bfd77ca4aa1567ace971d to your computer and use it in GitHub Desktop.
Save andytwoods/8cd21ea6d09bfd77ca4aa1567ace971d to your computer and use it in GitHub Desktop.
django testing, open a response in a browser
import tempfile
import webbrowser
import time
def tobrowser(response):
html_txt = response.content.decode("utf-8")
tmp = tempfile.NamedTemporaryFile(delete=False)
path = tmp.name + '.html'
f = open(path, 'w')
f.write(html_txt)
f.close()
webbrowser.open('file://' + path)
time.sleep(2)
tmp.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment