View function Extension Point

Description

The extension point abbreviation is vep.

Vep is a simple way for plugins to directly add routing functions, because in previous versions, routing was only allowed through blueprints.

The plugin needs to return the vep field via register. The returned vep data type can be dict, list, tuple.

The dict format is {rule:, view_func:}, which means that a single route is added. The dict content is the parameter of add_url_rule(), reference document add_url_rule, a common example is:

def vep():
    return "vep"

dict(rule="/vep", view_func=vep, endpoint="vep", methods=["GET", "POST"])

Other types are represented as multiple routes, and multiple dict data of the above type can be nested.

The Flask-PluginKit loads vep via _vep_handler(), this method will detect vep rules and specific content.

Example

  • Plugin registration for vep

def uploaded_file(filename):
    return send_from_directory(app.config['UPLOAD_FOLDER'], filename)

def upload_file():
    if request.method == 'POST':
        # save post file
        return redirect(url_for('uploaded_file', filename=filename))
    else:
        return '''
        <form method=post enctype=multipart/form-data>
            <input type=file name=file>
            <input type=submit value=Upload>
        </form>
        '''

def register():
    return dict(
        vep = [
            dict(
                rule="/uploads/<filename>",
                view_func=uploaded_file
            ),
            dict(
                rule="/upload",
                view_func=upload_file,
                methods=["GET", "POST"]
            )
        ]
    )
  • User Access

Access /upload display form, access the uploaded file via /uploads/filename.