Request in Flask from a Form in HTML is returning None Value, What should I Do?
I am getting no value on request in flask. It is returning None value.
I have tried changing the method but no use.
The flask code:
@app.route("/login/user/book")
def searchbook():
bookname=request.form.get("search")
return render_template("message.html",heading=bookname ,message=" ")
The webpage:
{% extends "layout.html" %}
{% block heading %}Welcome to BookSarkar{% endblock %}
{% block body %}
<p>Welcome {{ name }}</p>
<form action="{{ url_for('searchbook') }}" method="get" class="form-group">
<div class="form-group">
<input type="text" name="search" class="form-control col-md-6 mt-5 mx-auto" placeholder="Search books">
<p style="text-align:center;">
<button type ="submit" class="btn btn-primary mt-2 mx-auto">Search</button>
</p>
</div>
</form>
<div class="fixed-top m-2">
<a class="btn btn-outline-primary" href="{{ url_for('logout') }}" role="button" style="float:right;">Log out</a>
</div>
{% endblock %}
The message webpage:
{% extends "layout.html" %}
{% block heading %}{{ heading }}{% endblock %}
{% block body %}
{{ message }}
<a class="btn btn-primary" href="{{ url_for('index') }}" role="button">Return to Home Page</a>
{% endblock %}
The layout page has no bugs as all other pages are working fine. I expected the webpage to show the given input but it is showing None
python html flask bootstrap-4 jinja2
add a comment |
I am getting no value on request in flask. It is returning None value.
I have tried changing the method but no use.
The flask code:
@app.route("/login/user/book")
def searchbook():
bookname=request.form.get("search")
return render_template("message.html",heading=bookname ,message=" ")
The webpage:
{% extends "layout.html" %}
{% block heading %}Welcome to BookSarkar{% endblock %}
{% block body %}
<p>Welcome {{ name }}</p>
<form action="{{ url_for('searchbook') }}" method="get" class="form-group">
<div class="form-group">
<input type="text" name="search" class="form-control col-md-6 mt-5 mx-auto" placeholder="Search books">
<p style="text-align:center;">
<button type ="submit" class="btn btn-primary mt-2 mx-auto">Search</button>
</p>
</div>
</form>
<div class="fixed-top m-2">
<a class="btn btn-outline-primary" href="{{ url_for('logout') }}" role="button" style="float:right;">Log out</a>
</div>
{% endblock %}
The message webpage:
{% extends "layout.html" %}
{% block heading %}{{ heading }}{% endblock %}
{% block body %}
{{ message }}
<a class="btn btn-primary" href="{{ url_for('index') }}" role="button">Return to Home Page</a>
{% endblock %}
The layout page has no bugs as all other pages are working fine. I expected the webpage to show the given input but it is showing None
python html flask bootstrap-4 jinja2
Put a breakpoint atreturn render_template("message.html",heading=bookname ,message=" ")
in your flask code and inspect the value of bookname. Is it None or is it populated?
– Peter Dannemann
Dec 28 '18 at 18:05
@PeterDannemann I am new to this and dont know how to debug, that is why i am using the return render_template("message.html",heading=bookname ,message=" ") to test whether it is None or populated
– Rajreet Sarkar
Dec 28 '18 at 18:11
Ok just put ‘print(bookname)’ before that line. What does it print when you make a request?
– Peter Dannemann
Dec 28 '18 at 18:20
add a comment |
I am getting no value on request in flask. It is returning None value.
I have tried changing the method but no use.
The flask code:
@app.route("/login/user/book")
def searchbook():
bookname=request.form.get("search")
return render_template("message.html",heading=bookname ,message=" ")
The webpage:
{% extends "layout.html" %}
{% block heading %}Welcome to BookSarkar{% endblock %}
{% block body %}
<p>Welcome {{ name }}</p>
<form action="{{ url_for('searchbook') }}" method="get" class="form-group">
<div class="form-group">
<input type="text" name="search" class="form-control col-md-6 mt-5 mx-auto" placeholder="Search books">
<p style="text-align:center;">
<button type ="submit" class="btn btn-primary mt-2 mx-auto">Search</button>
</p>
</div>
</form>
<div class="fixed-top m-2">
<a class="btn btn-outline-primary" href="{{ url_for('logout') }}" role="button" style="float:right;">Log out</a>
</div>
{% endblock %}
The message webpage:
{% extends "layout.html" %}
{% block heading %}{{ heading }}{% endblock %}
{% block body %}
{{ message }}
<a class="btn btn-primary" href="{{ url_for('index') }}" role="button">Return to Home Page</a>
{% endblock %}
The layout page has no bugs as all other pages are working fine. I expected the webpage to show the given input but it is showing None
python html flask bootstrap-4 jinja2
I am getting no value on request in flask. It is returning None value.
I have tried changing the method but no use.
The flask code:
@app.route("/login/user/book")
def searchbook():
bookname=request.form.get("search")
return render_template("message.html",heading=bookname ,message=" ")
The webpage:
{% extends "layout.html" %}
{% block heading %}Welcome to BookSarkar{% endblock %}
{% block body %}
<p>Welcome {{ name }}</p>
<form action="{{ url_for('searchbook') }}" method="get" class="form-group">
<div class="form-group">
<input type="text" name="search" class="form-control col-md-6 mt-5 mx-auto" placeholder="Search books">
<p style="text-align:center;">
<button type ="submit" class="btn btn-primary mt-2 mx-auto">Search</button>
</p>
</div>
</form>
<div class="fixed-top m-2">
<a class="btn btn-outline-primary" href="{{ url_for('logout') }}" role="button" style="float:right;">Log out</a>
</div>
{% endblock %}
The message webpage:
{% extends "layout.html" %}
{% block heading %}{{ heading }}{% endblock %}
{% block body %}
{{ message }}
<a class="btn btn-primary" href="{{ url_for('index') }}" role="button">Return to Home Page</a>
{% endblock %}
The layout page has no bugs as all other pages are working fine. I expected the webpage to show the given input but it is showing None
python html flask bootstrap-4 jinja2
python html flask bootstrap-4 jinja2
asked Dec 28 '18 at 17:59
Rajreet SarkarRajreet Sarkar
93
93
Put a breakpoint atreturn render_template("message.html",heading=bookname ,message=" ")
in your flask code and inspect the value of bookname. Is it None or is it populated?
– Peter Dannemann
Dec 28 '18 at 18:05
@PeterDannemann I am new to this and dont know how to debug, that is why i am using the return render_template("message.html",heading=bookname ,message=" ") to test whether it is None or populated
– Rajreet Sarkar
Dec 28 '18 at 18:11
Ok just put ‘print(bookname)’ before that line. What does it print when you make a request?
– Peter Dannemann
Dec 28 '18 at 18:20
add a comment |
Put a breakpoint atreturn render_template("message.html",heading=bookname ,message=" ")
in your flask code and inspect the value of bookname. Is it None or is it populated?
– Peter Dannemann
Dec 28 '18 at 18:05
@PeterDannemann I am new to this and dont know how to debug, that is why i am using the return render_template("message.html",heading=bookname ,message=" ") to test whether it is None or populated
– Rajreet Sarkar
Dec 28 '18 at 18:11
Ok just put ‘print(bookname)’ before that line. What does it print when you make a request?
– Peter Dannemann
Dec 28 '18 at 18:20
Put a breakpoint at
return render_template("message.html",heading=bookname ,message=" ")
in your flask code and inspect the value of bookname. Is it None or is it populated?– Peter Dannemann
Dec 28 '18 at 18:05
Put a breakpoint at
return render_template("message.html",heading=bookname ,message=" ")
in your flask code and inspect the value of bookname. Is it None or is it populated?– Peter Dannemann
Dec 28 '18 at 18:05
@PeterDannemann I am new to this and dont know how to debug, that is why i am using the return render_template("message.html",heading=bookname ,message=" ") to test whether it is None or populated
– Rajreet Sarkar
Dec 28 '18 at 18:11
@PeterDannemann I am new to this and dont know how to debug, that is why i am using the return render_template("message.html",heading=bookname ,message=" ") to test whether it is None or populated
– Rajreet Sarkar
Dec 28 '18 at 18:11
Ok just put ‘print(bookname)’ before that line. What does it print when you make a request?
– Peter Dannemann
Dec 28 '18 at 18:20
Ok just put ‘print(bookname)’ before that line. What does it print when you make a request?
– Peter Dannemann
Dec 28 '18 at 18:20
add a comment |
1 Answer
1
active
oldest
votes
request.form
contains values submitted via post
or put
, while your form uses get
. Try using request.args.get("search")
instead of request.form.get("search")
It worked. Thank you.
– Rajreet Sarkar
Dec 28 '18 at 18:28
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f53962514%2frequest-in-flask-from-a-form-in-html-is-returning-none-value-what-should-i-do%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
request.form
contains values submitted via post
or put
, while your form uses get
. Try using request.args.get("search")
instead of request.form.get("search")
It worked. Thank you.
– Rajreet Sarkar
Dec 28 '18 at 18:28
add a comment |
request.form
contains values submitted via post
or put
, while your form uses get
. Try using request.args.get("search")
instead of request.form.get("search")
It worked. Thank you.
– Rajreet Sarkar
Dec 28 '18 at 18:28
add a comment |
request.form
contains values submitted via post
or put
, while your form uses get
. Try using request.args.get("search")
instead of request.form.get("search")
request.form
contains values submitted via post
or put
, while your form uses get
. Try using request.args.get("search")
instead of request.form.get("search")
answered Dec 28 '18 at 18:19
Tadeusz SznukTadeusz Sznuk
30113
30113
It worked. Thank you.
– Rajreet Sarkar
Dec 28 '18 at 18:28
add a comment |
It worked. Thank you.
– Rajreet Sarkar
Dec 28 '18 at 18:28
It worked. Thank you.
– Rajreet Sarkar
Dec 28 '18 at 18:28
It worked. Thank you.
– Rajreet Sarkar
Dec 28 '18 at 18:28
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.
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%2f53962514%2frequest-in-flask-from-a-form-in-html-is-returning-none-value-what-should-i-do%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
Put a breakpoint at
return render_template("message.html",heading=bookname ,message=" ")
in your flask code and inspect the value of bookname. Is it None or is it populated?– Peter Dannemann
Dec 28 '18 at 18:05
@PeterDannemann I am new to this and dont know how to debug, that is why i am using the return render_template("message.html",heading=bookname ,message=" ") to test whether it is None or populated
– Rajreet Sarkar
Dec 28 '18 at 18:11
Ok just put ‘print(bookname)’ before that line. What does it print when you make a request?
– Peter Dannemann
Dec 28 '18 at 18:20