Question

I have saved the validate code in session variable,and I use the web.py template to pass the session to the html page with $context.How can I compare it with user input code by javascript or transfer it to javascript code for comparing? Thanks.

Was it helpful?

Solution

No, you can not do that, you can only rennder the javascript(a part of html) use the session varibale, but after it is rendered, the html is fixed! So you can not use the session variable of tempalte context.

May you can try to generate a variable in the rendered html by using your template session variable.

e.g.:

<script type="text/javascript">
    var username = "$context.username";
</script>

or:

<script type="text/javascript">
    var session = {
        foo: "$context.foo",
        bar: "$context.bar",
        ...
    };
</script>

In your application code:

render = web.temlate.render('templaters', global={'context': session})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top