Flask requests.args keep variable in new app route
up vote
1
down vote
favorite
i am getting a variable using request.args. I would like to add another app route to obtain a new variable that will link to the client_id in the app route '/search/'. how do i keep this client_id variable when adding another app route?
from flask import Flask
from flask import render_template, url_for, request, redirect
from flask import make_response
app = Flask(__name__)
import pandas as pd
@app.route('/', methods=['GET'])
def index():
res = '''<form action="/search" method=>
<p><input type="text" name="query" value="test"></p>
<p><input type="submit" value="Search"></p>
<br />
</form>'''
return res
@app.route('/search', methods=["GET","POST"])
def suggestion():
client_id = request.args['query']
return render_template('untitled2.html')
if __name__ == '__main__':
app.run(debug=True)
for example, I want to add this app route
@app.route('/csv/')
def download_csv():
#can't figure out how to obtain the client_id var
client_id = ???
model_id=request.args['textid']
model_id1=request.args['textid1']
model_id2=request.args['textid2']
# return response
df=recommender.update_history(client_id, model_id, model_id1, model_id2)
df= recommender.get_csv()
resp = make_response(df.to_csv(encoding='iso-8859-1',index=False))
resp.headers["Content-Disposition"] = "attachment; filename=export.csv"
resp.headers["Content-Type"] = "text/csv"
return resp
here's what I have on my html template where i need to grab the variable that was formerly in request.args['text'] and send it to the new app route "/csv" along with the new form data:
untitled2.html:
<div class="form-group">
<h4>Suggestions for {{ request.args['text'] }} </h4>
<form action ="/csv">
<form method="POST">
<br>
<label>Enter 3 suggestions</label>
<br>
<input name="textid", placeholder="Suggested Model ID #", value="{{ request.form['textid'] }}"/>
<input name="textid1", placeholder="Suggested Model ID #", value="{{ request.form['textid1'] }}"/>
<input name="textid2", placeholder="Suggested Model ID #", value="{{ request.form['textid2'] }}"/>
<input type="submit" >
</form>
</div>
<h4>Entered Suggestions:{{ request.form['textid'] }} {{ request.form['textid1'] }} {{ request.form['textid2'] }} </h4>
flask jinja2 html-form
add a comment |
up vote
1
down vote
favorite
i am getting a variable using request.args. I would like to add another app route to obtain a new variable that will link to the client_id in the app route '/search/'. how do i keep this client_id variable when adding another app route?
from flask import Flask
from flask import render_template, url_for, request, redirect
from flask import make_response
app = Flask(__name__)
import pandas as pd
@app.route('/', methods=['GET'])
def index():
res = '''<form action="/search" method=>
<p><input type="text" name="query" value="test"></p>
<p><input type="submit" value="Search"></p>
<br />
</form>'''
return res
@app.route('/search', methods=["GET","POST"])
def suggestion():
client_id = request.args['query']
return render_template('untitled2.html')
if __name__ == '__main__':
app.run(debug=True)
for example, I want to add this app route
@app.route('/csv/')
def download_csv():
#can't figure out how to obtain the client_id var
client_id = ???
model_id=request.args['textid']
model_id1=request.args['textid1']
model_id2=request.args['textid2']
# return response
df=recommender.update_history(client_id, model_id, model_id1, model_id2)
df= recommender.get_csv()
resp = make_response(df.to_csv(encoding='iso-8859-1',index=False))
resp.headers["Content-Disposition"] = "attachment; filename=export.csv"
resp.headers["Content-Type"] = "text/csv"
return resp
here's what I have on my html template where i need to grab the variable that was formerly in request.args['text'] and send it to the new app route "/csv" along with the new form data:
untitled2.html:
<div class="form-group">
<h4>Suggestions for {{ request.args['text'] }} </h4>
<form action ="/csv">
<form method="POST">
<br>
<label>Enter 3 suggestions</label>
<br>
<input name="textid", placeholder="Suggested Model ID #", value="{{ request.form['textid'] }}"/>
<input name="textid1", placeholder="Suggested Model ID #", value="{{ request.form['textid1'] }}"/>
<input name="textid2", placeholder="Suggested Model ID #", value="{{ request.form['textid2'] }}"/>
<input type="submit" >
</form>
</div>
<h4>Entered Suggestions:{{ request.form['textid'] }} {{ request.form['textid1'] }} {{ request.form['textid2'] }} </h4>
flask jinja2 html-form
In html file, you are using request.args['text'], but in app.py you useclient_id = request.args['query']
... mistake ?
– Dinko Pehar
Nov 9 at 4:17
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
i am getting a variable using request.args. I would like to add another app route to obtain a new variable that will link to the client_id in the app route '/search/'. how do i keep this client_id variable when adding another app route?
from flask import Flask
from flask import render_template, url_for, request, redirect
from flask import make_response
app = Flask(__name__)
import pandas as pd
@app.route('/', methods=['GET'])
def index():
res = '''<form action="/search" method=>
<p><input type="text" name="query" value="test"></p>
<p><input type="submit" value="Search"></p>
<br />
</form>'''
return res
@app.route('/search', methods=["GET","POST"])
def suggestion():
client_id = request.args['query']
return render_template('untitled2.html')
if __name__ == '__main__':
app.run(debug=True)
for example, I want to add this app route
@app.route('/csv/')
def download_csv():
#can't figure out how to obtain the client_id var
client_id = ???
model_id=request.args['textid']
model_id1=request.args['textid1']
model_id2=request.args['textid2']
# return response
df=recommender.update_history(client_id, model_id, model_id1, model_id2)
df= recommender.get_csv()
resp = make_response(df.to_csv(encoding='iso-8859-1',index=False))
resp.headers["Content-Disposition"] = "attachment; filename=export.csv"
resp.headers["Content-Type"] = "text/csv"
return resp
here's what I have on my html template where i need to grab the variable that was formerly in request.args['text'] and send it to the new app route "/csv" along with the new form data:
untitled2.html:
<div class="form-group">
<h4>Suggestions for {{ request.args['text'] }} </h4>
<form action ="/csv">
<form method="POST">
<br>
<label>Enter 3 suggestions</label>
<br>
<input name="textid", placeholder="Suggested Model ID #", value="{{ request.form['textid'] }}"/>
<input name="textid1", placeholder="Suggested Model ID #", value="{{ request.form['textid1'] }}"/>
<input name="textid2", placeholder="Suggested Model ID #", value="{{ request.form['textid2'] }}"/>
<input type="submit" >
</form>
</div>
<h4>Entered Suggestions:{{ request.form['textid'] }} {{ request.form['textid1'] }} {{ request.form['textid2'] }} </h4>
flask jinja2 html-form
i am getting a variable using request.args. I would like to add another app route to obtain a new variable that will link to the client_id in the app route '/search/'. how do i keep this client_id variable when adding another app route?
from flask import Flask
from flask import render_template, url_for, request, redirect
from flask import make_response
app = Flask(__name__)
import pandas as pd
@app.route('/', methods=['GET'])
def index():
res = '''<form action="/search" method=>
<p><input type="text" name="query" value="test"></p>
<p><input type="submit" value="Search"></p>
<br />
</form>'''
return res
@app.route('/search', methods=["GET","POST"])
def suggestion():
client_id = request.args['query']
return render_template('untitled2.html')
if __name__ == '__main__':
app.run(debug=True)
for example, I want to add this app route
@app.route('/csv/')
def download_csv():
#can't figure out how to obtain the client_id var
client_id = ???
model_id=request.args['textid']
model_id1=request.args['textid1']
model_id2=request.args['textid2']
# return response
df=recommender.update_history(client_id, model_id, model_id1, model_id2)
df= recommender.get_csv()
resp = make_response(df.to_csv(encoding='iso-8859-1',index=False))
resp.headers["Content-Disposition"] = "attachment; filename=export.csv"
resp.headers["Content-Type"] = "text/csv"
return resp
here's what I have on my html template where i need to grab the variable that was formerly in request.args['text'] and send it to the new app route "/csv" along with the new form data:
untitled2.html:
<div class="form-group">
<h4>Suggestions for {{ request.args['text'] }} </h4>
<form action ="/csv">
<form method="POST">
<br>
<label>Enter 3 suggestions</label>
<br>
<input name="textid", placeholder="Suggested Model ID #", value="{{ request.form['textid'] }}"/>
<input name="textid1", placeholder="Suggested Model ID #", value="{{ request.form['textid1'] }}"/>
<input name="textid2", placeholder="Suggested Model ID #", value="{{ request.form['textid2'] }}"/>
<input type="submit" >
</form>
</div>
<h4>Entered Suggestions:{{ request.form['textid'] }} {{ request.form['textid1'] }} {{ request.form['textid2'] }} </h4>
flask jinja2 html-form
flask jinja2 html-form
asked Nov 8 at 21:02
Julia Dills
758
758
In html file, you are using request.args['text'], but in app.py you useclient_id = request.args['query']
... mistake ?
– Dinko Pehar
Nov 9 at 4:17
add a comment |
In html file, you are using request.args['text'], but in app.py you useclient_id = request.args['query']
... mistake ?
– Dinko Pehar
Nov 9 at 4:17
In html file, you are using request.args['text'], but in app.py you use
client_id = request.args['query']
... mistake ?– Dinko Pehar
Nov 9 at 4:17
In html file, you are using request.args['text'], but in app.py you use
client_id = request.args['query']
... mistake ?– Dinko Pehar
Nov 9 at 4:17
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You can keep your client_id
variable, by adding it to session, save it in cookie or
use g
object.
For session, just use instead of client_id
, session['client_id'] = request.args['query']
. You can always get it with session['client_id']
. Additionally, you must set secret key in config of app like so app.config['SECRET_KEY'] = 'My secret key'
.
Read more about sessions here.
1
thanks! worked perfectly!
– Julia Dills
Nov 9 at 14:34
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You can keep your client_id
variable, by adding it to session, save it in cookie or
use g
object.
For session, just use instead of client_id
, session['client_id'] = request.args['query']
. You can always get it with session['client_id']
. Additionally, you must set secret key in config of app like so app.config['SECRET_KEY'] = 'My secret key'
.
Read more about sessions here.
1
thanks! worked perfectly!
– Julia Dills
Nov 9 at 14:34
add a comment |
up vote
1
down vote
accepted
You can keep your client_id
variable, by adding it to session, save it in cookie or
use g
object.
For session, just use instead of client_id
, session['client_id'] = request.args['query']
. You can always get it with session['client_id']
. Additionally, you must set secret key in config of app like so app.config['SECRET_KEY'] = 'My secret key'
.
Read more about sessions here.
1
thanks! worked perfectly!
– Julia Dills
Nov 9 at 14:34
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You can keep your client_id
variable, by adding it to session, save it in cookie or
use g
object.
For session, just use instead of client_id
, session['client_id'] = request.args['query']
. You can always get it with session['client_id']
. Additionally, you must set secret key in config of app like so app.config['SECRET_KEY'] = 'My secret key'
.
Read more about sessions here.
You can keep your client_id
variable, by adding it to session, save it in cookie or
use g
object.
For session, just use instead of client_id
, session['client_id'] = request.args['query']
. You can always get it with session['client_id']
. Additionally, you must set secret key in config of app like so app.config['SECRET_KEY'] = 'My secret key'
.
Read more about sessions here.
answered Nov 9 at 4:29
Dinko Pehar
7992324
7992324
1
thanks! worked perfectly!
– Julia Dills
Nov 9 at 14:34
add a comment |
1
thanks! worked perfectly!
– Julia Dills
Nov 9 at 14:34
1
1
thanks! worked perfectly!
– Julia Dills
Nov 9 at 14:34
thanks! worked perfectly!
– Julia Dills
Nov 9 at 14:34
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53216089%2fflask-requests-args-keep-variable-in-new-app-route%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
In html file, you are using request.args['text'], but in app.py you use
client_id = request.args['query']
... mistake ?– Dinko Pehar
Nov 9 at 4:17