2016-09-17 3 views
0

こんにちは私は簡単なアンケートアプリを作成しようとしています。フォームを完了すると、アンケートの結果を表示できるページに移動します。フラスコ内の別のページにリンクするフォーム検証

現在の問題は「このメソッドは要求されたURLに対して許可されていません」

Sever.py:

from flask import Flask, flash, session, render_template, request, redirect, url_for 
app = Flask(__name__) 
app.secret_key = 'very secret' 


@app.route('/') 
def index(): 
    return render_template('index.html') 


@app.route('/process', methods=['POST']) 
def process(): 
    if len(request.form['name']) < 1 or len(request.form['comments']) < 1: 
     flash("you need to fill out the name and comments") 
    else: 
     return redirect(url_for('createUser')) 
    return redirect('/') 


@app.route('/results', methods=['POST']) 
def createUser(): 
    return render_template('results.html', name=request.form['name'], 
     location=request.form['location'], favLang=request.form['favLang'], 
    comments=request.form['comments']) 
    return redirect('/') 

app.run(debug=True) 

のIは、名前やコメントを入力してくださいいけないときに私は私のフラッシュを取得becuase/ELSEなステートメントが動作するかどうか。私はちょうどapp.route( '/ results')に適切に行くことができません。私はちょうどvaidation形式でユーザーを作成し、結果ページにリンクされ@davidismからのコメントへ

@app.route('/process', methods=['POST']) 
def process(): 
    if len(request.form['name']) < 1 or len(request.form['comments']) < 1: 
     flash("you need to fill out the name and comments") 
    else: 
     return redirect('/results') 
    return redirect('/') 
+0

ユーザーを作成するだけで、別のビュー/リクエストにリダイレクトする必要はなく、すでに最初のリクエストにすべてのデータがあります。 – davidism

+0

あなたの天才。助けてくれてありがとう。 (あなたが知っているトンネルビジョン) – BatsAuto

答えて

0

感謝:私はまた、ノー成功を収めてこれでそれを試してみました。

ここにある:

@app.route('/process', methods=['POST']) 
def process(): 
    if len(request.form['name']) < 1 or len(request.form['comments']) < 1: 
     flash("you need to fill out the name and comments") 
    else: 
     return render_template('results.html', name=request.form['name'], 
      location=request.form['location'], favLang=request.form['favLang'], 
      comments=request.form['comments']) 
    return redirect('/') 

私はそれがあるが、私はcertianly私はそれが望んでいたように動作し、「修正」方法を知ってはいけません。

関連する問題