0

I have one html file which contain submission form.

I want to use this HTML form in django with model and view.

I dont want to use form class in html like

<form method="post" action="">

{% csrf_token %}

{{ form }}

<input type="submit" value="Register"/>
</form>

I want to use complete form code in HTML and use django model to store that data in database.

How can I do that?

8
  • you may access individual field through {{ form.field_name }} Commented Apr 11, 2016 at 5:26
  • I dont want to access fields but i want to use some jquery on that form. Commented Apr 11, 2016 at 5:28
  • use the above code as it is. It should generate related html code. Open ur favourite browser and do insepect the element. Find it's id and apply jquery func on that particular elem id. Commented Apr 11, 2016 at 5:35
  • @AvinashRaj Thanks for helping me out. :) Commented Apr 11, 2016 at 5:53
  • 1
    @Sayse I found some javascript but for that form field id is necessary and i was not aware of that fact that id will generated by django automatically Commented Apr 11, 2016 at 7:02

1 Answer 1

1

Please update the question that you want to use jQuery.Django by defaults generate id for its form element.

As avinash already said you can always inspect the element and get the id and classses but some time we need custom class in that case you can use something like.

If you want to write your own custom fields.

class myForm(forms.ModelForm):
    class Meta:
        model = ModeName
        widgets = {
            'field_one': forms.TextInput(attrs={'id':'foo', 'name':'foo'})
            'field_two': forms.TextInput(attrs={'id':'bar', 'name':'bar'})
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @burning for helping me. I was not aware of that fact of django. Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.