Home » Odeon Blogs » Nai Chng »

Django Shortcuts: render

Django Shortcuts: render

One of the great things about being a web developer is that you're always constantly learning new tricks to make your job easier. Yesterday, I found this really neat django shortcut render.

According to Django docs:

  1. render
  2. render(request, template[, dictionary][, context_instance][, content_type][, status][, current_app])
  3. Combines a given template with a given context dictionary and returns an HttpResponse object with that rendered text.
  4. render() is the same as a call to render_to_response() with a context_instance argument that forces the use of a RequestContext.

So basically, you go from having something like this: 

  1. return render_to_response(template, locals(), context_instance=RequestContext(request))

to this:

  1. return render(request, template, locals())

I like! :)

Category: Django

Tagged as: django django-shortcuts render

Leave a Comment :




Page generated in: 0.19s