【发布时间】:2021-08-31 12:57:02
【问题描述】:
我是 Django 的新手,我意识到这是一个非常愚蠢的问题,但是,当我将对象放入 HTML 代码中以从数据库中调用 index 时,我只收到我正在调用的文本:List of news(item.title)(item.title)(item.title)(item.title)
views.py:
from django.shortcuts import render
from django.http import HttpResponse
from .models import News
def index(request):
news = News.objects.all()
res = '<hi>List of news</h1>'
for item in news:
res += f'<div><p>(item.title)</p></div>'
return HttpResponse(res)
【问题讨论】:
-
请浏览一次 Django 的教程。看官方的:docs.djangoproject.com/en/3.2/intro 具体你应该多注意 Part 3 docs.djangoproject.com/en/3.2/intro/tutorial03 讲模板系统。
-
好的,我再读一遍
标签: python html python-3.x django