[Answer]-Django – Registration form default value of fields

1👍

Rather than defining it in the Meta class, try defining it your form definition like so:

email = forms.EmailField(label='email', 
                    widget=forms.TextInput(attrs={'placeholder': 'example@domain.com'}))

Or you could do this in jQuery like so:

<script type="text/javascript" >
    $(document).ready(function(){
        $("#id_username").attr('placeholder', '{{form.username.label}}');
        $("#id_email").attr('placeholder', '{{form.email.label}}');
    });
</script>

And then define your label='example@domain.com'.

Edit

You could try reinitializing an empty form after your user logs in like so:

if request.method == "POST":
    rf = RegistrationForm(request.POST)
    if rf.is_valid():
        # This reinitializes an empty form before rendering a response
        rf = LoginForm()
        return render_to_response(...)
👤alacy

0👍

Just to use placeholder for that

class Meta:
    model = User
    widgets = {
        'password': forms.PasswordInput(),
        'email': EmailInput(attrs={'placeholder': 'something@something.com'}),
    }

Leave a comment