Skip to content
Back to Blog

Django template tags placeholders

Rich Jones

Jan 13, 2017 10:00:00 AM

Extremely quick blog post!

Here's how to make a crude template tag which lets you add the HTML5 'placeholder' attribute to your form field inputs and textareas in a Django template.

  from django.template import Library
  import re
  register = Library()
  def placeholder(value, token):
  value.field.widget.attrs["placeholder"] = token
  return value
view raw hosted with ❤ by GitHub


Drop this in /yourproject/yourapp/templatetags/ as, and then you're done!

Written By:

Rich Jones

Want to get our totally not sh*tty weekly newsletter?

Sometimes The Wayfarer is funny, sometimes insightful, but always the least spammy newsletter this side of Tatooine.