This part of the documentation covers all interfaces of Flask-WTF.
Flask-specific subclass of WTForms SecureForm class.
If formdata is not specified, this will use flask.request.form. Explicitly pass formdata = None to prevent this.
Parameters: |
|
---|
Wraps hidden fields in a hidden DIV tag, in order to keep XHTML compliance.
New in version 0.3.
Parameters: | fields – list of hidden field names. If not provided will render all hidden fields, including the CSRF field. |
---|
Checks if form has been submitted. The default case is if the HTTP method is PUT or POST.
Check if the csrf data is valid.
Parameters: | data – the csrf string to be validated. |
---|
Checks if form has been submitted and if so runs validate. This is a shortcut, equivalent to form.is_submitted() and form.validate()
Validates a ReCaptcha.
Werkzeug-aware subclass of wtforms.FileField
Provides a has_file() method to check if its data is a FileStorage instance with an actual file.
Deprecated : | synonym for data |
---|
Return True iff self.data is a FileStorage with file data
Validates that the uploaded file is allowed by the given Flask-Uploads UploadSet.
Parameters: |
|
---|
You can also use the synonym file_allowed.
Validates that field has a file.
Parameters: | message – error message |
---|
You can also use the synonym file_required.
Renders an input with type “search”.
Represents an <input type="search">.
Renders an input with type “url”.
Represents an <input type="url">.
Renders an input with type “email”.
Represents an <input type="email">.
Renders an input with type “tel”.
Represents an <input type="tel">.
Renders an input with type “number”.
Represents an <input type="number">.
Represents an <input type="number">.
Renders an input with type “range”.
Represents an <input type="range">.
Represents an <input type="range">.
Enable csrf protect for Flask.
Register it with:
app = Flask(__name__)
CsrfProtect(app)
And in the templates, add the token input:
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
If you need to send the token via AJAX, and there is no form:
<meta name="csrf_token" content="{{ csrf_token() }}" />
You can grab the csrf token with JavaScript, and send the token together.
A decorator that set the error response handler.
It accepts one parameter reason:
@csrf.error_handler
def csrf_error(reason):
return render_template('error.html', reason=reason)
By default, it will return a 400 response.
A decorator that can exclude a view from csrf protection.
Remember to put the decorator above the route:
csrf = CsrfProtect(app)
@csrf.exempt
@app.route('/some-view', methods=['POST'])
def some_view():
return
Generate csrf token code.
Parameters: |
|
---|
Check if the given data is a valid csrf token.
Parameters: |
|
---|