Created
September 18, 2020 13:49
-
-
Save andytwoods/8cd21ea6d09bfd77ca4aa1567ace971d to your computer and use it in GitHub Desktop.
django testing, open a response in a browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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