Pass a string value from one route function to other in python [duplicate]












0
















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.










share|improve this question















marked as duplicate by davidism flask
Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

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
















0
















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.










share|improve this question















marked as duplicate by davidism flask
Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

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














0












0








0









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.










share|improve this question

















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 11:13









Madhuri Patel

873621




873621










asked Jan 2 at 7:51









StolaineStolaine

112




112




marked as duplicate by davidism flask
Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

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 flask
Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

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



















  • 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












1 Answer
1






active

oldest

votes


















0














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)





share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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)





    share|improve this answer




























      0














      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)





      share|improve this answer


























        0












        0








        0







        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)





        share|improve this answer













        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)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 8:15









        GeekSambhuGeekSambhu

        699819




        699819

















            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

            Npm cannot find a required file even through it is in the searched directory