Django网站未显示字典值
我正在为Django使用VS代码。我不确定为什么,但是默认的Django网站没有显示预期的输出。输出忽略了字典值。
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
context = {
'name': 'Patrick',
'age' : 23,
'nationality':'British',
}
return render(request, 'index.html', context)
<h1>
Welcome, {{name}}<br> You are {{age}} years old.
</h1>
(在服务器网站中输出)
Welcome,
You are years old.
I am using VS code for django. I am not sure why but the default django website is not showing the expected output. The output is ignoring the dictionary values.
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
context = {
'name': 'Patrick',
'age' : 23,
'nationality':'British',
}
return render(request, 'index.html', context)
<h1>
Welcome, {{name}}<br> You are {{age}} years old.
</h1>
(output in server website)
Welcome,
You are years old.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码正确,但可能会导致预期输出不显示两件事。
Your code is correct but there might be two things that might cause the expected output not to show.
尝试以这种方式发送上下文:
您的HTML文件应该是这样的:
try sending the context this way :
your HTML file should be something like this: