Python 对用户的帖子做出反应

Python 对用户的帖子做出反应,python,flask,jinja2,flask-sqlalchemy,Python,Flask,Jinja2,Flask Sqlalchemy,不管我下面的具体问题是什么,在同一页面上多次回复用户帖子的有效方法是什么。这样,页面上的每一篇渐进式文章都可以捕获新请求并显示新信息?如果我没有正确描述问题,请原谅 我正在尝试构建一个页面,以响应用户的帖子。但我遇到了一个问题: 错误的请求 浏览器(或代理)发送了此服务器无法接收的请求 明白 我猜测是因为在我当前的解决方案中: @app.route('/survey', methods = ['GET', 'POST'])$ @cont

不管我下面的具体问题是什么,在同一页面上多次回复用户帖子的有效方法是什么。这样,页面上的每一篇渐进式文章都可以捕获新请求并显示新信息?如果我没有正确描述问题,请原谅

我正在尝试构建一个页面,以响应用户的帖子。但我遇到了一个问题:

错误的请求

浏览器(或代理)发送了此服务器无法接收的请求 明白

我猜测是因为在我当前的解决方案中:

@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)
一旦我收到带有调查标题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 %}
{%extends“base.html”%}
{%block content%}
{%如果不是组织\u id%}
{%用于组织\类中的组织。query.all()%}
{{organization.name}
{%endfor%}
{%elif不是调查头\u id%}
{{organization_selected.name}
{所选组织中的调查\u头的百分比。调查\u头。全部()%}
{{survey_header.name}
{%endfor%}
{%elif不是调查\u部分\u id%}
嗨

{%else%} {%endif%} {%endblock%}

我应该怎么做?

错误请求
通常是访问不存在的参数的结果,例如
Request.form['organization\u id']
,当表单中没有具有该名称的元素时

您的调查路线将始终尝试从表单中检索
组织id
,因为您将其设置为
None
,在测试之前没有任何更改。在第二篇文章中,模板根本不创建
organization\u id
元素,因为该值是从上一篇文章中传递的,因此当
survey()
仍试图检索时,您会看到一个错误

您需要某种方法将提交的值从一个步骤传递到下一个步骤。例如,您可以将它们写入表单中的隐藏或禁用字段,以便在每次发布后获取它们并将其发送回模板,或者将您的状态存储在其他位置,如
会话