'forms.ContactForm object' has no attribute 'hidden_tag'

前端 未结 4 2071
孤街浪徒
孤街浪徒 2021-02-13 05:53

I am trying to create a contact form using flask but keep getting this error when the page is rendered.

\'forms.ContactForm object\' has no attribute \'hidden_         


        
4条回答
  •  眼角桃花
    2021-02-13 06:05

    The error that you're seeing is telling you that forms.ContactForm has no method called "hidden_tag". You're referencing that method on the 6th line of contact.html like this:

    {{ form.hidden_tag() }}
    

    According to the flask documentation, this is the correct way to implement CSRF protection.

    I would start by removing the line that references "form.hidden_tag()", then see if your form works. Then go back and implement CSRF protection per those instructions from the documentation.

提交回复
热议问题