Created
October 16, 2013 12:15
-
-
Save martync/7006775 to your computer and use it in GitHub Desktop.
When testing a django application, sometime you just want to see what's happening on your html content. That does the trick.
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 time | |
from datetime import datetime | |
from subprocess import call | |
def show_in_browser(response): | |
""" | |
Write the response content into a temporary HTML file and | |
open it into your default browser. | |
> client = Client() | |
> response = client.get('/some/page/') | |
> show_in_browser(response) | |
""" | |
file_path = '/tmp/django_test_show_in_browser_%s.html' % datetime.now().strftime('%Y%m%d%H%M%S') | |
f = open(file_path, 'w') | |
f.write('%s\n' % response.content) | |
call(["open", file_path]) | |
time.sleep(5) | |
call(["rm", file_path]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment