if statement in html (with jinja2) - where should I edit to make it work?
UPDATE : There was whitespaces in session['sid']
and that was why this didn't work!
I'm using python, flask, jinja2, html.
This is a part of my html code.
<h1>session['sid']</h1> <!--shows 'admin'-->
<ul>
% if session['sid'] != 'admin' %
<li> <a href="/sendmail">SEND MAIL</a> </li>
<li> <a href="">MAIL BOX</a> </li>
% endif %
session
is a dictionary type data sent to this html from python and I double checked that session['sid']
is 'admin'
. But those hyperlinks still show up, so it looks like if
statements doesn't work. Somewhere in the code, there is also session['sid']!='admin'
which also doesn't work. I googled about if
statement example in html, but I don't still understand where I made mistake. Can anybody let me know what I am missing here?
I have tried excluding '
around admin
or using % if equal session['sid'] 'admin'%
instead.
python html flask jinja2
|
show 1 more comment
UPDATE : There was whitespaces in session['sid']
and that was why this didn't work!
I'm using python, flask, jinja2, html.
This is a part of my html code.
<h1>session['sid']</h1> <!--shows 'admin'-->
<ul>
% if session['sid'] != 'admin' %
<li> <a href="/sendmail">SEND MAIL</a> </li>
<li> <a href="">MAIL BOX</a> </li>
% endif %
session
is a dictionary type data sent to this html from python and I double checked that session['sid']
is 'admin'
. But those hyperlinks still show up, so it looks like if
statements doesn't work. Somewhere in the code, there is also session['sid']!='admin'
which also doesn't work. I googled about if
statement example in html, but I don't still understand where I made mistake. Can anybody let me know what I am missing here?
I have tried excluding '
around admin
or using % if equal session['sid'] 'admin'%
instead.
python html flask jinja2
what error you are getting?
– Harsha B
Nov 12 '18 at 6:18
why not just debug the HTML? Insertingsession['sid']
will display its value and you can then determine whether it is or is not equal to'admin'
– Attack68
Nov 12 '18 at 7:00
@Attack68 edited my code.
– PuffedRiceCrackers
Nov 12 '18 at 7:23
@HarshaB There's no error. Just the if statement doesn't work.
– PuffedRiceCrackers
Nov 12 '18 at 7:26
Can you verifytype(session['sid'])
is astr
, just in case it's not another type that just stringifies toadmin
?
– Amadan
Nov 12 '18 at 7:37
|
show 1 more comment
UPDATE : There was whitespaces in session['sid']
and that was why this didn't work!
I'm using python, flask, jinja2, html.
This is a part of my html code.
<h1>session['sid']</h1> <!--shows 'admin'-->
<ul>
% if session['sid'] != 'admin' %
<li> <a href="/sendmail">SEND MAIL</a> </li>
<li> <a href="">MAIL BOX</a> </li>
% endif %
session
is a dictionary type data sent to this html from python and I double checked that session['sid']
is 'admin'
. But those hyperlinks still show up, so it looks like if
statements doesn't work. Somewhere in the code, there is also session['sid']!='admin'
which also doesn't work. I googled about if
statement example in html, but I don't still understand where I made mistake. Can anybody let me know what I am missing here?
I have tried excluding '
around admin
or using % if equal session['sid'] 'admin'%
instead.
python html flask jinja2
UPDATE : There was whitespaces in session['sid']
and that was why this didn't work!
I'm using python, flask, jinja2, html.
This is a part of my html code.
<h1>session['sid']</h1> <!--shows 'admin'-->
<ul>
% if session['sid'] != 'admin' %
<li> <a href="/sendmail">SEND MAIL</a> </li>
<li> <a href="">MAIL BOX</a> </li>
% endif %
session
is a dictionary type data sent to this html from python and I double checked that session['sid']
is 'admin'
. But those hyperlinks still show up, so it looks like if
statements doesn't work. Somewhere in the code, there is also session['sid']!='admin'
which also doesn't work. I googled about if
statement example in html, but I don't still understand where I made mistake. Can anybody let me know what I am missing here?
I have tried excluding '
around admin
or using % if equal session['sid'] 'admin'%
instead.
python html flask jinja2
python html flask jinja2
edited Nov 12 '18 at 13:22
PuffedRiceCrackers
asked Nov 12 '18 at 5:55
PuffedRiceCrackersPuffedRiceCrackers
486
486
what error you are getting?
– Harsha B
Nov 12 '18 at 6:18
why not just debug the HTML? Insertingsession['sid']
will display its value and you can then determine whether it is or is not equal to'admin'
– Attack68
Nov 12 '18 at 7:00
@Attack68 edited my code.
– PuffedRiceCrackers
Nov 12 '18 at 7:23
@HarshaB There's no error. Just the if statement doesn't work.
– PuffedRiceCrackers
Nov 12 '18 at 7:26
Can you verifytype(session['sid'])
is astr
, just in case it's not another type that just stringifies toadmin
?
– Amadan
Nov 12 '18 at 7:37
|
show 1 more comment
what error you are getting?
– Harsha B
Nov 12 '18 at 6:18
why not just debug the HTML? Insertingsession['sid']
will display its value and you can then determine whether it is or is not equal to'admin'
– Attack68
Nov 12 '18 at 7:00
@Attack68 edited my code.
– PuffedRiceCrackers
Nov 12 '18 at 7:23
@HarshaB There's no error. Just the if statement doesn't work.
– PuffedRiceCrackers
Nov 12 '18 at 7:26
Can you verifytype(session['sid'])
is astr
, just in case it's not another type that just stringifies toadmin
?
– Amadan
Nov 12 '18 at 7:37
what error you are getting?
– Harsha B
Nov 12 '18 at 6:18
what error you are getting?
– Harsha B
Nov 12 '18 at 6:18
why not just debug the HTML? Inserting
session['sid']
will display its value and you can then determine whether it is or is not equal to 'admin'
– Attack68
Nov 12 '18 at 7:00
why not just debug the HTML? Inserting
session['sid']
will display its value and you can then determine whether it is or is not equal to 'admin'
– Attack68
Nov 12 '18 at 7:00
@Attack68 edited my code.
– PuffedRiceCrackers
Nov 12 '18 at 7:23
@Attack68 edited my code.
– PuffedRiceCrackers
Nov 12 '18 at 7:23
@HarshaB There's no error. Just the if statement doesn't work.
– PuffedRiceCrackers
Nov 12 '18 at 7:26
@HarshaB There's no error. Just the if statement doesn't work.
– PuffedRiceCrackers
Nov 12 '18 at 7:26
Can you verify
type(session['sid'])
is a str
, just in case it's not another type that just stringifies to admin
?– Amadan
Nov 12 '18 at 7:37
Can you verify
type(session['sid'])
is a str
, just in case it's not another type that just stringifies to admin
?– Amadan
Nov 12 '18 at 7:37
|
show 1 more comment
1 Answer
1
active
oldest
votes
i tested your template (named as template.j2
) with jinja-cli
and this data file (named as data.json
):
"session":
"sid": "admin"
command line:
# pip install jinja-cli
# jinja -d data.json template.j2
the result is correct:
<ul>
</ul>
so i think the template is fine; you may want to dump session
in python code to see if flask really sets its properly; flask.session
is a proxy; under the hood it is a signed cookie (doc
); so you probably should also check your cookie settings;
Thanks! I added a header to show what is insession['sid']
as above, and this is getting more frustrating. At least it seems to mean flask sets it properly.
– PuffedRiceCrackers
Nov 12 '18 at 7:24
@PuffedRiceCrackers i'd recommend upload the whole project in that case so that we can see if anything wrong with its configuration;
– Cyker
Nov 12 '18 at 22:30
In fact,session['sid']
had whitespaces, something likeadmin
.
– PuffedRiceCrackers
Nov 13 '18 at 2:01
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%2f53256557%2fif-statement-in-html-with-jinja2-where-should-i-edit-to-make-it-work%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
i tested your template (named as template.j2
) with jinja-cli
and this data file (named as data.json
):
"session":
"sid": "admin"
command line:
# pip install jinja-cli
# jinja -d data.json template.j2
the result is correct:
<ul>
</ul>
so i think the template is fine; you may want to dump session
in python code to see if flask really sets its properly; flask.session
is a proxy; under the hood it is a signed cookie (doc
); so you probably should also check your cookie settings;
Thanks! I added a header to show what is insession['sid']
as above, and this is getting more frustrating. At least it seems to mean flask sets it properly.
– PuffedRiceCrackers
Nov 12 '18 at 7:24
@PuffedRiceCrackers i'd recommend upload the whole project in that case so that we can see if anything wrong with its configuration;
– Cyker
Nov 12 '18 at 22:30
In fact,session['sid']
had whitespaces, something likeadmin
.
– PuffedRiceCrackers
Nov 13 '18 at 2:01
add a comment |
i tested your template (named as template.j2
) with jinja-cli
and this data file (named as data.json
):
"session":
"sid": "admin"
command line:
# pip install jinja-cli
# jinja -d data.json template.j2
the result is correct:
<ul>
</ul>
so i think the template is fine; you may want to dump session
in python code to see if flask really sets its properly; flask.session
is a proxy; under the hood it is a signed cookie (doc
); so you probably should also check your cookie settings;
Thanks! I added a header to show what is insession['sid']
as above, and this is getting more frustrating. At least it seems to mean flask sets it properly.
– PuffedRiceCrackers
Nov 12 '18 at 7:24
@PuffedRiceCrackers i'd recommend upload the whole project in that case so that we can see if anything wrong with its configuration;
– Cyker
Nov 12 '18 at 22:30
In fact,session['sid']
had whitespaces, something likeadmin
.
– PuffedRiceCrackers
Nov 13 '18 at 2:01
add a comment |
i tested your template (named as template.j2
) with jinja-cli
and this data file (named as data.json
):
"session":
"sid": "admin"
command line:
# pip install jinja-cli
# jinja -d data.json template.j2
the result is correct:
<ul>
</ul>
so i think the template is fine; you may want to dump session
in python code to see if flask really sets its properly; flask.session
is a proxy; under the hood it is a signed cookie (doc
); so you probably should also check your cookie settings;
i tested your template (named as template.j2
) with jinja-cli
and this data file (named as data.json
):
"session":
"sid": "admin"
command line:
# pip install jinja-cli
# jinja -d data.json template.j2
the result is correct:
<ul>
</ul>
so i think the template is fine; you may want to dump session
in python code to see if flask really sets its properly; flask.session
is a proxy; under the hood it is a signed cookie (doc
); so you probably should also check your cookie settings;
edited Nov 12 '18 at 6:13
answered Nov 12 '18 at 6:07
CykerCyker
2,82553245
2,82553245
Thanks! I added a header to show what is insession['sid']
as above, and this is getting more frustrating. At least it seems to mean flask sets it properly.
– PuffedRiceCrackers
Nov 12 '18 at 7:24
@PuffedRiceCrackers i'd recommend upload the whole project in that case so that we can see if anything wrong with its configuration;
– Cyker
Nov 12 '18 at 22:30
In fact,session['sid']
had whitespaces, something likeadmin
.
– PuffedRiceCrackers
Nov 13 '18 at 2:01
add a comment |
Thanks! I added a header to show what is insession['sid']
as above, and this is getting more frustrating. At least it seems to mean flask sets it properly.
– PuffedRiceCrackers
Nov 12 '18 at 7:24
@PuffedRiceCrackers i'd recommend upload the whole project in that case so that we can see if anything wrong with its configuration;
– Cyker
Nov 12 '18 at 22:30
In fact,session['sid']
had whitespaces, something likeadmin
.
– PuffedRiceCrackers
Nov 13 '18 at 2:01
Thanks! I added a header to show what is in
session['sid']
as above, and this is getting more frustrating. At least it seems to mean flask sets it properly.– PuffedRiceCrackers
Nov 12 '18 at 7:24
Thanks! I added a header to show what is in
session['sid']
as above, and this is getting more frustrating. At least it seems to mean flask sets it properly.– PuffedRiceCrackers
Nov 12 '18 at 7:24
@PuffedRiceCrackers i'd recommend upload the whole project in that case so that we can see if anything wrong with its configuration;
– Cyker
Nov 12 '18 at 22:30
@PuffedRiceCrackers i'd recommend upload the whole project in that case so that we can see if anything wrong with its configuration;
– Cyker
Nov 12 '18 at 22:30
In fact,
session['sid']
had whitespaces, something like admin
.– PuffedRiceCrackers
Nov 13 '18 at 2:01
In fact,
session['sid']
had whitespaces, something like admin
.– PuffedRiceCrackers
Nov 13 '18 at 2:01
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%2f53256557%2fif-statement-in-html-with-jinja2-where-should-i-edit-to-make-it-work%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
what error you are getting?
– Harsha B
Nov 12 '18 at 6:18
why not just debug the HTML? Inserting
session['sid']
will display its value and you can then determine whether it is or is not equal to'admin'
– Attack68
Nov 12 '18 at 7:00
@Attack68 edited my code.
– PuffedRiceCrackers
Nov 12 '18 at 7:23
@HarshaB There's no error. Just the if statement doesn't work.
– PuffedRiceCrackers
Nov 12 '18 at 7:26
Can you verify
type(session['sid'])
is astr
, just in case it's not another type that just stringifies toadmin
?– Amadan
Nov 12 '18 at 7:37