How do I customize registration form HTML?

34 views
Skip to first unread message

Tom Tanner

unread,
Nov 30, 2017, 7:50:35 PM11/30/17
to Django users
The HTML for the user registration form looks like this:
<form method="post">
 {% csrf_token %}
 {{ registration_form.as_p }}
 <button type="submit">Register</button>
</form>

I understand that the `registration_form.as_p` line automatically gives me the form's HTML. But I'd like to customize that HTML. For instance, I'd like the label text to be placeholders instead. How do I do this?

If it helps, `registration_form` is `UserCreationForm()`

Luiz Guilherme Schiefler de Arruda

unread,
Dec 1, 2017, 8:32:36 AM12/1/17
to Django users
Hello,

I don't know if this tutorial will help you. It helped me a lot.


It is a very good serie teaching how to build a board.

yingi keme

unread,
Dec 1, 2017, 9:26:17 AM12/1/17
to django...@googlegroups.com
Intead of rendering it with the as_p. You can render them individually.
ie

{{form.username}}

 In the forms.py, in each of the fields, add widget attributes.

def MyForm(forms.ModelForm):
    name = forms.CharField(label='name',     widgets=forms.TextInput(attrs={'placeholder':'Name', 'class':'yourInputFieldClassName'}))



Yingi Kem
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/12490918-6d56-4079-ab53-9b8cb6f9fd9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

yingi keme

unread,
Dec 1, 2017, 9:27:21 AM12/1/17
to django...@googlegroups.com


Yingi Kem

On 1 Dec 2017, at 3:25 PM, yingi keme <ying...@gmail.com> wrote:

Intead of rendering it with the as_p. You can render them individually.
ie

{{form.username}}

 In the forms.py, in each of the fields, add widget attributes.

def MyForm(forms.ModelForm):
    name = forms.CharField(label='name',     widget=forms.TextInput(attrs={'placeholder':'Name', 'class':'yourInputFieldClassName'}))

yingi keme

unread,
Dec 1, 2017, 9:30:18 AM12/1/17
to django...@googlegroups.com
Hey, i made a mistake in the previous reply. Its widget and not widgets. The correct code is:


Intead of rendering it with the as_p. You can render them individually.
ie

{{form.username}}

 In the forms.py, in each of the fields, add widget attributes.

def MyForm(forms.ModelForm):
    name = forms.CharField(label='name',     widget=forms.TextInput(attrs={'placeholder':'Name', 'class':'yourInputFieldClassName'}))


Yingi Kem

On 1 Dec 2017, at 1:50 AM, Tom Tanner <dontsende...@gmail.com> wrote:

--

Mario Gudelj

unread,
Dec 1, 2017, 5:56:58 PM12/1/17
to django...@googlegroups.com
I’d recommend you to look at crispy forms as well. 

Tom Tanner

unread,
Dec 1, 2017, 6:47:04 PM12/1/17
to Django users
Where can I find all the options like {{ form.name }} ?
Reply all
Reply to author
Forward
0 new messages