Python 在django中传递html模板中的变量

Python 在django中传递html模板中的变量,python,django,django-views,django-templates,Python,Django,Django Views,Django Templates,我需要创建一个html django模板一个段落,其中包含一个select DINAMICALL创建的段落。我从txt文件中读取值并将其存储在dict中,当我调用render以响应时,我传递该dict,但当我尝试在模板中打印其值时,它不会打印任何内容。以下是我的看法: 视图.py def index(request): context = { 'variable': 'This has been sent' } return render(request, 'index.

我需要创建一个html django模板一个段落,其中包含一个select DINAMICALL创建的段落。我从txt文件中读取值并将其存储在dict中,当我调用render以响应时,我传递该dict,但当我尝试在模板中打印其值时,它不会打印任何内容。以下是我的看法:

视图.py

def index(request):
    context = {
    'variable': 'This has been sent'
    }
return render(request, 'index.html', context)
这是html模板中的打印:

<p>Hey Dear! {{variable}}</p>
这是我在HTML模板中调用的变量:

<p>Hey Dear! {{variable}}</p>
index.html

<p>Hey Dear! {{variable}}</p>
嘿,亲爱的!{{variable}}

有人能帮我吗?

试试这个:

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

    return render(request, 'index.html', context)
在模板中:

<p>Hey Dear! {{variable}}</p>
嘿,亲爱的!{{variable}}


欢迎来到堆栈溢出。请看如何写一篇文章。目前,你展示的例子应该可以很好地工作,因此你的问题是不可复制的。它是否显示了“嗨,亲爱的?”?