首页 > 解决方案 > 字典的键值没有显示在 html 中由 django

问题描述

我刚开始学习 Django,我遇到了这个问题,我的键“hello”的键值“hello world”没有显示在 HTML 页面中,我希望你们能帮助我理解这段代码

主页.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>this is html page</h1>
{{ hello }}
</body>
</html>

网址.py

from django.urls import path
import view

urlpatterns = [
    path('',view.homepage),
]

视图.py

from django.http import HttpResponse
from django.shortcuts import render

def homepage(request):
    return render(request, "homepage.html", {'hello':'hello world'})

标签: djangopython-3.x

解决方案


<p>{{ hello }}</p> 

在里面写你的代码

标签


推荐阅读