简体   繁体   中英

Pass a variable in the html template in django

I need to create an html django template a paragraph with a select dinamically created. I read values from a txt file and I store it in a dict, when I call the render to response I pass this dict but when I try to print its values in the template it doesn't print anything. This is my views:

views.py

def index(request):
    context = {
    'variable': 'This has been sent'
    }
return render(request, 'index.html', context)

and this is the print in the html template:

And this is the variable I'm calling in the HTML template:

index.html

<p>Hey Dear! {{variable}}</p>

Can anyone help me?

try this:

    def index(request):
        variable = 'This has been sent'
        context = {
        'variable': variable
        }

    return render(request, 'index.html', context)

in template:

<p>Hey Dear! {{variable}}</p>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM