0

以下の私の特定の問題に関係なく、同じページに投稿されたユーザーに複数回応答する効果的な方法は何ですか。ページの各プログレッシブ投稿で、新しいリクエストをキャプチャして新しい情報を表示できるようにするには?問題を正しく説明していない場合はご容赦ください。

ユーザーの投稿に反応するページを作成しようとしています。しかし、私は:に遭遇しています

要求の形式が正しくありません

ブラウザ(またはプロキシ)が、このサーバーが理解できない要求を送信しました。

私の現在のソリューションでは、次のように推測しています。

@app.route('/survey', methods = ['GET', 'POST'])$                              
@contributer_permission.require(403)$  
def survey():
    organization_id = None
    survey_header_id = None
    survey_section_id = None

    organization_selected = None
    survey_header_selected = None
    survey_section_selected = None

    if request.method== 'POST':
        if not organization_id:
            organization_id = request.form['organization_id']
            organization_selected = Organization.query.get(organization_id)

        elif not survey_header_id:
            survey_header_id = request.form['survey_header_id']
            survey_header_selected = SurveyHeader.query.get(survey_header_id)
        elif not survey_section_id:
            pass
        else:
            pass

    return render_template('survey.html',
        organization_class = Organization,
        organization_selected = organization_selected,
        organization_id = organization_id,
        survey_header_id = survey_header_id,
        survey_header_selected = survey_header_selected,
        survey_section_id = survey_section_id,
        survey_section_selected = survey_section_selected)

私がsurvey_header_idを載せた投稿を受け取ったら。それは再ループし、

organization_id becomes none 

これが付随するhtml/jsonです

{% extends "base.html" %}
{% block content %}
    <div class ="entries"> <!-- should be a DIV in your style! -->
    <form action="{{url_for('survey') }}" method="post" class="add-entry"/>
            <dl>
            {% if not organization_id %}
                {% for organization in organization_class.query.all() %}
                    <dt><input type="radio", name="organization_id",
                    value="{{ organization.id }}"/>{{ organization.name }}</dt>
                {% endfor %}
                <dt><input type ="submit", name="submit_organization"/>
            {% elif not survey_header_id %}
                <h1>{{ organization_selected.name }}</h1>
                {% for survey_header in organization_selected.survey_headers.all() %}
                    <dt><input type="radio", name="survey_header_id"
                    value="{{ survey_header.id }}"/>{{ survey_header.name }}
                {% endfor %}
                <dt><input type ="submit", name="submit_survey_header"/>
            {% elif not survey_section_id %}
                <p>hi</p>
            {% else %}
            {% endif %}
            <dl>
    </form>
    </div>
{% endblock %}

私は何をすべきですか?

4

1 に答える 1

1

Bad Requestrequest.form['organization_id']これは通常、フォームにその名前の要素がない場合など、存在しないパラメータにアクセスした結果です。

organization_idに設定しているため、調査ルートは常にフォームから取得しようとしますNone。テストする前にフォームを変更する必要はありません。2番目の投稿では、値が前の投稿から渡されたため、テンプレートはorganization_id要素をまったく作成しません。そのため、survey()それでも取得しようとするとエラーが表示されます。

送信された値をあるステップから次のステップに渡す方法が必要です。たとえば、フォーム内の非表示または無効なフィールドにそれらを書き込んで、各投稿の後にそれらを取得してテンプレートに送り返したり、状態をのような別の場所に保存したりできますsession

于 2013-01-16T22:00:23.787 に答える