Skip to content
Advertisement

access variable in template from views.py – Django

This is my first time messing with django and I am having trouble passing variables from a view function to a template html file.

views.py

JavaScript

and I am trying to send userdata over to index.html like so:

JavaScript

However, I am getting either no variables showing up on the screen or I get an error like this:

JavaScript

I assume I am missing something basic in index.html to pass variables from the views.py to the index.html file

Advertisement

Answer

this is not how django template works, DTL (django template language) has some rules.

try this

JavaScript

refer this

https://docs.djangoproject.com/en/4.0/ref/templates/api/#rendering-a-context

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement