Pass a string value from one route function to other in python [duplicate]
This question already has an answer here:
How to pass a variable between Flask pages?
2 answers
I am working on a flask project.
I have created a from with following description
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired
class SearchRestaurantForm(FlaskForm):
query = StringField('Query', validators=[DataRequired()])
searchButton = SubmitField('Search')
This form is accessed in a route function named search
as shown below.
@app.route("/search", methods=['GET', 'POST'])
def search():
form = SearchRestaurantForm()
if form.validate_on_submit():
query_ = form.query.data
return redirect('/result?query='+query_)
return render_template('search.html', title='Search', form = form)
I want to use the data of the StringField query
in another route function named result
as shown below.
@app.route("/result", methods=['GET'])
def result():
query__ = query_
restaurants = find_appro_res(query__)
return render_template('result.html', res_list=restaurants)
I don't know how can I access the str
of search
function in result
function.
I am new in flask.
python flask
marked as duplicate by davidism
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 14:03
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to pass a variable between Flask pages?
2 answers
I am working on a flask project.
I have created a from with following description
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired
class SearchRestaurantForm(FlaskForm):
query = StringField('Query', validators=[DataRequired()])
searchButton = SubmitField('Search')
This form is accessed in a route function named search
as shown below.
@app.route("/search", methods=['GET', 'POST'])
def search():
form = SearchRestaurantForm()
if form.validate_on_submit():
query_ = form.query.data
return redirect('/result?query='+query_)
return render_template('search.html', title='Search', form = form)
I want to use the data of the StringField query
in another route function named result
as shown below.
@app.route("/result", methods=['GET'])
def result():
query__ = query_
restaurants = find_appro_res(query__)
return render_template('result.html', res_list=restaurants)
I don't know how can I access the str
of search
function in result
function.
I am new in flask.
python flask
marked as duplicate by davidism
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 14:03
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
You should only use one single function here...
– bruno desthuilliers
Jan 2 at 8:39
add a comment |
This question already has an answer here:
How to pass a variable between Flask pages?
2 answers
I am working on a flask project.
I have created a from with following description
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired
class SearchRestaurantForm(FlaskForm):
query = StringField('Query', validators=[DataRequired()])
searchButton = SubmitField('Search')
This form is accessed in a route function named search
as shown below.
@app.route("/search", methods=['GET', 'POST'])
def search():
form = SearchRestaurantForm()
if form.validate_on_submit():
query_ = form.query.data
return redirect('/result?query='+query_)
return render_template('search.html', title='Search', form = form)
I want to use the data of the StringField query
in another route function named result
as shown below.
@app.route("/result", methods=['GET'])
def result():
query__ = query_
restaurants = find_appro_res(query__)
return render_template('result.html', res_list=restaurants)
I don't know how can I access the str
of search
function in result
function.
I am new in flask.
python flask
This question already has an answer here:
How to pass a variable between Flask pages?
2 answers
I am working on a flask project.
I have created a from with following description
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired
class SearchRestaurantForm(FlaskForm):
query = StringField('Query', validators=[DataRequired()])
searchButton = SubmitField('Search')
This form is accessed in a route function named search
as shown below.
@app.route("/search", methods=['GET', 'POST'])
def search():
form = SearchRestaurantForm()
if form.validate_on_submit():
query_ = form.query.data
return redirect('/result?query='+query_)
return render_template('search.html', title='Search', form = form)
I want to use the data of the StringField query
in another route function named result
as shown below.
@app.route("/result", methods=['GET'])
def result():
query__ = query_
restaurants = find_appro_res(query__)
return render_template('result.html', res_list=restaurants)
I don't know how can I access the str
of search
function in result
function.
I am new in flask.
This question already has an answer here:
How to pass a variable between Flask pages?
2 answers
python flask
python flask
edited Jan 2 at 11:13
Madhuri Patel
873621
873621
asked Jan 2 at 7:51
StolaineStolaine
112
112
marked as duplicate by davidism
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 14:03
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by davidism
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 14:03
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
You should only use one single function here...
– bruno desthuilliers
Jan 2 at 8:39
add a comment |
You should only use one single function here...
– bruno desthuilliers
Jan 2 at 8:39
You should only use one single function here...
– bruno desthuilliers
Jan 2 at 8:39
You should only use one single function here...
– bruno desthuilliers
Jan 2 at 8:39
add a comment |
1 Answer
1
active
oldest
votes
If you want the request parameter to use in endpoints in flask, you can always use flask's request To access incoming request data, you can use the global request
object of flask.
For solving your problem modify the result
function as below:
from flask import request
@app.route("/result", methods=['GET'])
def result():
query__ = request.args.get('query') # This will capture the request argument
restaurants = find_appro_res(query__)
return render_template('result.html', res_list=restaurants)
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you want the request parameter to use in endpoints in flask, you can always use flask's request To access incoming request data, you can use the global request
object of flask.
For solving your problem modify the result
function as below:
from flask import request
@app.route("/result", methods=['GET'])
def result():
query__ = request.args.get('query') # This will capture the request argument
restaurants = find_appro_res(query__)
return render_template('result.html', res_list=restaurants)
add a comment |
If you want the request parameter to use in endpoints in flask, you can always use flask's request To access incoming request data, you can use the global request
object of flask.
For solving your problem modify the result
function as below:
from flask import request
@app.route("/result", methods=['GET'])
def result():
query__ = request.args.get('query') # This will capture the request argument
restaurants = find_appro_res(query__)
return render_template('result.html', res_list=restaurants)
add a comment |
If you want the request parameter to use in endpoints in flask, you can always use flask's request To access incoming request data, you can use the global request
object of flask.
For solving your problem modify the result
function as below:
from flask import request
@app.route("/result", methods=['GET'])
def result():
query__ = request.args.get('query') # This will capture the request argument
restaurants = find_appro_res(query__)
return render_template('result.html', res_list=restaurants)
If you want the request parameter to use in endpoints in flask, you can always use flask's request To access incoming request data, you can use the global request
object of flask.
For solving your problem modify the result
function as below:
from flask import request
@app.route("/result", methods=['GET'])
def result():
query__ = request.args.get('query') # This will capture the request argument
restaurants = find_appro_res(query__)
return render_template('result.html', res_list=restaurants)
answered Jan 2 at 8:15


GeekSambhuGeekSambhu
699819
699819
add a comment |
add a comment |
You should only use one single function here...
– bruno desthuilliers
Jan 2 at 8:39