嗨谢谢你的帮助,我的编码很差。
要点:我正在做一个 Django 项目,将数据从数据库传递到前端;但是现在我什至无法将 Django 的任何视图传递到模板中,我怀疑我传递了错误的变量类型;请对您的想法发表评论。
这是我在 views.py 上的代码:
from django.shortcuts import render
def index (requset):
return render(requset,'myapp/index.html') # link to be able open frountend
def testdex(requset):
text = "hello world"
context ={'mytext' : text }
return render(requset,'myapp/inculdes.html', context)
所以我的变量将被传递到扩展到索引页面的 inculdes
这是我在 inculdes.html 中的代码:
{% exntends "myapp/index.html" %}
{% block includes %}
{{ mytext }}
{% endblock includes %}
这是我在 index.html 上的代码:
<body>
{% block includes %} {% endblock includes %}
</body>
再次感谢您给我时间来帮助我,如果能给我写一些代码,我将不胜感激,因为我会尝试整整一周来解决这个问题
原文由 Rookies DJ 发布,翻译遵循 CC BY-SA 4.0 许可协议
你可以尝试这样的事情
视图.py
包括.html
并确保您已在 settings.py 中设置模板路径