Login

Tag "response"

Snippet List

yet another render_to_response decorator

This one takes a template path as an argument. Return dictionary with template values from your view. It's simple as: @render_to_template('posts/post_list.html') def api_get_all(request): return {'test': 'testing!'}

  • render_to_response
  • decorator
  • response
Read More

Load response.content in browser (for debugging)

When debugging tests you frequently need to inspect response content, making a pdb. set_trace() breakpoint and printing response.content but html isn't enough human readable (even for programmers :D) so, why not open it in your browser? Suposse you save this code in utils.py and you break your testcase as this: response = self.client.get(self.url) import pdb; pdb.set_trace() Then: (pdb) from utils import load_response_on_firefox (pdb) load_response_on_firefox(response) Ta-Da!

  • debug
  • testing
  • response
  • response.content
Read More

View response's content in a browser while testing

I often insert `pdb.set_trace()` in my test cases to debug and examine behavior. When tests fail with assertions like `assertContains(response, 'Some text')`, it would be useful to see the response's contents in a browser window. This snippet does just that. Simply put this code in a python script on your `PYTHONPATH` and import/call the function when the debugger starts. Only tested on Ubuntu and you might want to change `URL_OPENER` to whatever you want to open the URLs. Simple, but hopefully useful.

  • debug
  • test
  • response
Read More

Another JsonResponse

Another `JsonResponse` class, including comment wrapping. Extensions to other kinds of CSRF protection should be obvious. Good explanations of why such protections are needed would make excellent comments on this snippet. This depends on the `json_encode` method in [snippet 800](http://www.djangosnippets.org/snippets/800/).

  • json
  • response
  • jsonresponse
Read More

Callable Class View

Instead of using a function for your views, this allows you to use a class. For your urls definition it works just as it normally does.

  • view
  • callable
  • response
Read More

8 snippets posted so far.