ข้ามไปเนื้อหา

ผลต่างระหว่างรุ่นของ "CuneiForm"

เพิ่มขึ้น 835 ไบต์ ,  16 เมษายน 2567
บรรทัดที่ 861: บรรทัดที่ 861:
=== All-in-one Route ===
=== All-in-one Route ===
Below is an example for Flask route that handles everything for a single-form page. This format is the most frequently written, since most CuneiForms are used on a unique page (or a set of pages that share the same route anyway).
Below is an example for Flask route that handles everything for a single-form page. This format is the most frequently written, since most CuneiForms are used on a unique page (or a set of pages that share the same route anyway).
<syntaxhighlight lang='python' line=1>
@<blueprint>.route("<submit_path>", methods=["POST"])
def <function_name>(*args):
    form = <CuneiForm_class>.init_form(...)
    if <check_if_fetch>:
        # Fetch, calculate, modify data to display on the form.
        return {'<field_name0>':<value0>, '<field_name1>':<value1>, ...}
    elif <check_if_submit>:
        if form.validate_on_submit():
            data_dict = {}
            # Do something
            return jsonify(data_dict)
        else:
            return jsonify(dict(err=form.errors))
    # Below this point is the preparation for Flask's render_template.
    # Initiate search tables to be used in the form.
    search_tb0 = <CuneiTable_class>(...)
    search_tb1 = <CuneiTable_class>(...)
    ...
    return render_template("<template_path>", ...)
</syntaxhighlight>


{{The Tenko Shrine}}
{{The Tenko Shrine}}