POST
から他のテンプレートへのメッセージを渡すことができます。特定の青写真の構造とルート/ビューの編集を参照してください。 _update_test
ルートにINGのPOST
後Flaskリダイレクトのルートを2回入力する
、フラスコのredirect()
機能。私から提供されたもの(それは私がbrowse_tests
ルートが入力されていることを私のデバッガで見ることができ、>> about to redirect
次に印刷し、メッセージの内容が期待されている通り参照>> about to render template
は、browse_tests
経路が二度目に入力されbase_browse_test.html
がレンダリングされているページの前に、
問題がコンソールに出力され、message
コンポーネントは、要求からなくなっているので、テンプレートは、(空のメッセージでレンダリングmessage = ''
)。ページがレンダリングされる前にもう一度>> about to render template
が印刷されています。
私はここで何が欠けていますか?
EDIT:ここで青写真構造は
root/webapp/__init__.py
ある:(このファイルの全体がat this pastebinを見出すことができる)
def create_app('development'):
webapp = Flask(__name__)
...
from .mod_tests import tests as tests_blueprint
webapp.register_blueprint(tests_blueprint, url_prefix='/tests')
return webapp
root/webapp/mod_tests/__init__.py
:
from flask import Blueprint
tests = Blueprint('tests', __name__)
from . import manage_tests_views
root/webapp/mod_tests/manage_tests_views.py
:
@tests.route('/_update_test', methods=['POST'])
def update_test():
...
print 'about to redirect'
return redirect(url_for('tests.browse_tests', message={"main":"foo message content"}))
@tests.route('/browse_tests', methods=['GET'])
@login_required
def browse_tests():
if request.args.get('message'):
message = request.args['message']
else:
message = ''
print 'about to render template'
return render_template('tests/base_browse_tests.html',
message=message)
デバッガの有無にかかわらず実行は違いはありません。
request.accept_mimetypes
は、最初の要求(メッセージ完全な、要求に含まれるクエリ文字列)に('*/*', 1)
を含むMIMEAccept dict
に等しく、第二、空のクエリ文字列要求に('text/html', 1), ('image/webp', 1), ('application/xhtml+xml', 1), ('application/xml', 0.9), ('*/*', 0.8)
を含んでいます。これは何か手掛かりですか?request.cookies['session']
文字列値が変更されない、dubuggerは
request.fullpath
はまず、通知無傷の要求にu'/tests/browse_tests?notification=<encoded json>'
に等しいです(私のIDEで青に回して)それがないと考えているようだが。request.fullpath
まず、通知インタクトな要求上の第二、通知無し要求request.is_xhr
==True
にu'/tests/browse_tests?'
に等しいです。第2の通知不要の要求では、request.environ['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
の2番目の要求では、False
であり、2番目の要求には存在しません。request.environ['HTTP_UPGRADE_INSECURE_REQUESTS'] is absent from the first request, and equals
「1'`、第2の要求
問題を再現できません。 [編集]に[mcve]を含めるようにしてください。 – davidism