python - Access Javascript variable in Django Template -
is there way access javascript
variable in django
template tags
?
can ,
<!doctype html> <html> <body> <script> var javascriptvar=0; </script> {% if javascriptvar==0 %} {% else %} {% endif %} </body> </html>
no, django template compiled server side. sent client browser executes javascript. nothing changed javascript executing on client browser can have affect on template. it's late @ point.
however javascript make request server more information. or pre-compute value on server before send client. if more explicit trying should able help.
you can of course use django templates set javascript variables.
<script> var myvar = '{{ py_var }}'; </script>
Comments
Post a Comment