![](/img/trans.png)
[英]Python Django how can't render my variables from views.py on html file
[英]python django variables from views.py to html show the code intead of the value
我正在尝试从 sqlite 打印我的产品问题是浏览器中的结果是代码本身而不是值。
视图.py:
from django.shortcuts import render
from django.http import HttpResponse
from .models import Product
def index(request):
products = Product.objects.all()
return render(request, 'index.html', {'dict': products})
索引.html:
<ul>
{% for prod in dict %}
<li>{{ prod.name }}</li>
{% endfor %}
</ul>
浏览器中的结果是:
{% for prod in dict %}
{{ prod.name }}
{% endfor %}
为了解决这个问题,您需要通过运行服务器检查 index.html
python manage.py runserver
并转到导致 index.html 的 url
如果浏览器中的结果像你说的那样,你是直接打开 HTML 文件吗? 因为如果 Django 呈现模板它不会显示这个。 即使数据错误或什么都没有,它也不会显示任何内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.