2017-04-07 4 views
0

現在、login()ルートをテスト中ですが、リダイレクトに問題があります。 メインインデックスページにリダイレクトしたいと思います。ヘルプの理解が必要です。Flask url_for()

マイ認証青写真は、次のようになります。また

from flask import Blueprint, render_template, request, redirect, url_for 

mod = Blueprint('auth', __name__, url_prefix='/auth') 


@mod.route('/login', methods=['GET', 'POST']) 
def login(): 
    if request.method == 'POST': 
     return redirect(url_for('general.index')) 
    return render_template('auth/login.html') 

@mod.route('/logout', methods=['GET', 'POST']) 
def logout(): 
    # Delete session token 
    return render_template('auth/logout.html') 

@mod.route('/tokeninfo') 
def token_info(): 
    return render_template('auth/tokeninfo.html') 

、私のgeneral青写真を次のように定義されます

from flask import Blueprint, render_template 

mod = Blueprint('general', __name__) 


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

しかし、毎回私は私がにリダイレクト/loginルート上にフォームを送信しますlocalhost:5000/authであり、404 page not found errorを受け取ります。

私は、次の方法でreturn redirect(url_for('general.index'))を調整しようとしているが、どれも成功しませんでした:

  • return redirect(url_for(general.index))
  • return redirect(url_for('general.index'))
  • return redirect(url_for('../general.index'))

EDIT:

それはと思われます提出するログインフォームは/ auth上のPOSTだけであり、/ auth/login上ではPOSTではありません。これはサーバーログに表示されます:

127.0.0.1 - - [07/Apr/2017 15:06:59] "GET /auth/login HTTP/1.1" 200 - 
404 Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. 
127.0.0.1 - - [07/Apr/2017 15:07:03] "POST /auth HTTP/1.1" 404 - 

私は何かが分からない/わからないのですか? ありがとうございます

答えて

0

問題はテンプレートにありました!私のログインテンプレートで

は、私が以前持っていた:今のリダイレクトが動作している

<form action="/auth/login" method="post" class="form-horizontal"> 

<form action="/auth" method="post" class="form-horizontal"> 

しかし、私は青写真パワードアプリに移行しておりますので、私は次の変更が必要予想通り。