Skip to content

Instantly share code, notes, and snippets.

@martync
Created October 16, 2013 12:15
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 martync/7006775 to your computer and use it in GitHub Desktop.
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.
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