Placeholder Workaround

We’ve still been working with Django on a redesign of a site’s blog module.  Still liking the tool- it’s a bit tricky to figure out initially (the url routing in took me way too long to wrap my head around- and I wouldn’t say I’m fully clear on most of it), but overall it’s so useful.

But in any bargain, there are downsides.  We were customizing the log in screen to get away from the default Django scheme (to try not to scream “We used a template for this!”).  Got the template overriding process down, but ran into an issue on something that should have been real simple.

We wanted to add placeholder text to the username/password fields (we were trying to create a slick, no-label login form).  But the actual input fields are generated ‘behind the scenes’ by Django.  Usually very useful, as then we don’t have to do it ourselves, but if there’s something it doesn’t include by default (like placeholder text), it can be tough to add it in (at least for a Python newbie like me).

I did some Googling and saw some smarter folks than I found a way to do it directly in the model (though it did look more complicated when using Django’s default admin panel log in), but my experience is mostly in Javascript, so that’s what I used.  It was really simple once I thought about it properly- just a call to the input field’s “placeholder” attribute to set it to “username” and “password” and we were good to go!

Sometimes it’s best to fall back on your strengths (at least, that’s what they tell me- and I tell myself JS is my strength!).


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s