2013-01-15 4 views
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를 들고 게시물을 받으면. 그것은이

{% 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 %} 

내가 무슨 일을해야 첨부 된 HTML/JSON이며 여기에 reloops 및

organization_id becomes none 

?

답변

1

Bad Request은 일반적으로 해당 이름의 양식에 요소가없는 경우 request.form['organization_id']과 같이 존재하지 않는 매개 변수에 액세스 한 결과입니다.

설문 조사 경로는 None으로 설정되어 있기 때문에 항상 양식에서 organization_id을 검색하려고 시도하며 테스트하기 전에 변경 사항이 없습니다. 두 번째 게시물에서는 survey()이 여전히 검색하려고 시도 할 때 오류를 볼 수 있도록 이전 우편에서 값이 전달 되었기 때문에 템플릿에 organization_id 요소가 전혀 생성되지 않습니다.

제출 된 값을 한 단계에서 다음 단계로 전달하는 방법이 필요합니다. 예를 들어 폼의 숨겨진 필드 나 사용 불가능한 필드에 글을 써서 각 포스트 이후 서식 파일로 다시 보내거나 session과 같은 상태로 저장할 수 있습니다.