Reputation: 9
I want to set placeholder inside text inputs, and I still don't know how to do this. I tried to add attributes but they didnt work and text is still showing above inputs. Here's my code:
forms.py
class LoginForm(forms.Form):
username = forms.Charfield(widget = forms.TextInput),
password = forms.Charfield(widget = forms.PasswordInput)
and that form is creating something like this:
html
<div class="row">
<div class="col-8"> </div>
<div class="col-4">
<p><span style="font-size:50px; color:#ac3b61;">Welcome!</span></p>
<form action="/account/login/" method="post">
<p><label for="id_username">Username:</label> <input type="text" name="username" autofocus="" autocapitalize="none" autocomplete="username" maxlength="150" required="" id="id_username"></p>
<p><label for="id_password">Password:</label> <input type="password" name="password" autocomplete="current-password" required="" id="id_password"></p>
<input type="hidden" name="csrfmiddlewaretoken" value="gkh34TNSATaWHP3f3c9Qmp1msf6nazSd9hAoKsTPlHtMWFN4nNIYOwkpx9iXcCer">
<input type="hidden" name="next" value="/account/">
<p><input type="submit" value="Login"></p>
<p><a href="/account/password_reset/">Forgot your password?</a></p>
<p>Don't have an account? Register <a href="/account/register/">here</a>. </p>
</form>
</div>
</div>
Upvotes: 0
Views: 64
Reputation: 1673
You can use attrs
option in the fields like this:
class LoginForm(forms.Form):
username = forms.CharField(widget = forms.TextInput(
attrs={ 'placeholder': 'Enter Username' }
)),
password = forms.CharField(widget = forms.PasswordInput(
attrs={ 'placeholder': 'Enter Password' }
))
Upvotes: 1