0

I am new to Django and am using Django's user auth package (django.contrib.auth) for user login, password reset, etc.

Now, while everything works just fine, on the logon form, I'd like to use the html-placeholder property. How can I use / populate this? I did find some answers (e.g. this one) but I do not understand where to place this code, how to extend the view / form or even the model (e.g. adding new fields) as this gets delivered with the standard package.

Right now, I have added the following: forms.py from django import forms from django.contrib.auth.forms import AuthenticationForm

class LoginForm(forms.Form):
  username = forms.CharField(label='username')
  password = forms.CharField(label='password')

  def __init__(self, *args, **kwargs):
      super(LoginForm, self).__init__(*args, **kwargs)
      self.fields['username'].widget.attrs['placeholder'] = 'Username'
      self.fields['password '].widget.attrs['placeholder'] = 'Password'

I am not sure what I need to do in urls.py or models.py or anywhere else for the code to be executed.

DevKing
  • 211
  • 5
  • 14
  • There are different approaches possible. It would help if you showed us your form and html. – HenryM Sep 08 '18 at 19:47
  • Well, that's my point... I am not sure what to do. When I looked at the link provided, I am not too sure how to add / extend the same. – DevKing Sep 09 '18 at 20:30

2 Answers2

0

I found the following solution:

  • installed bootstrap4
  • using the following tag in my html:

{% bootstrap_field form.password field_class="field" placeholder="Password" show_label=False %}

DevKing
  • 211
  • 5
  • 14
0

I believe by adding the widgets to your forms init, when you instantiate the form in your template the placeholder should appear like intended. Did you just try rendering your form such as {{form}} in the template and see if it rendered it? I dont think bootstrap4 is necessary but it is a great tool.

K.Pardo
  • 141
  • 1
  • 13