Dalvtor
Dalvtor

Reputation: 3286

django form without id=id_fieldname

I have the following form in django:

class Person(forms.Form):
    first_name = forms.CharField()
    last_name = forms.CharField()
    age = forms.IntegerField()

When I render the form, the html output is the following:

<input id="id_age" name="age" type="number">

Is it possible to NOT include the input id?

My desired output would be:

<input name="age" type="number">

I don't want to change the id, i want the input to not have the id attribute at all.

Upvotes: 2

Views: 914

Answers (2)

Daniel Roseman
Daniel Roseman

Reputation: 599490

I can't imagine what difference it makes, but you can use the auto_id attribute when instantiating the form in your view to turn off IDs altogether.

form = Person(auto_id=False) 

Upvotes: 2

Vijesh Venugopal
Vijesh Venugopal

Reputation: 1641

Please check the code below:

class Person(forms.Form):
    first_name = forms.CharField(label=u'First Name', 
                                widget=forms.TextInput(attrs = {"id":"set_your_id"}),
                                max_length=30)

Upvotes: 1

Related Questions