忽略标题。我有问题显示文字写的,并保存在管理页面上。我刚刚创建了一个新的应用程序,名字是关于。使用命令python manage.py启动应用程序关于和所有下面的文件都在这个应用程序内。
Models.py
from django.db import models
# Create your models here.
class About(models.Model):
title = "About me"
discription = models.TextField()
def __str__(self):
return self.titleadmin.py
from django.contrib import admin
from .models import About
# Register your models here.
admin.site.register(About)
# Register your models hereviews.py:
from django.shortcuts import render
from django.http import HttpRequest
from .models import About
# Create your views here.
def about(request):
abouts = About.objects.all()
return render(request, 'about/about.html', {'abouts': abouts})urls.py
from django.urls import path
from . import views
app_name = 'about'
urlpatterns = [
path('', views.about, name='about'),
]about.html
<p style="color: white;">{{ abouts.discription }}</p>问题是描述中写的文字没有显示在about.html页面上。请帮帮我。
发布于 2020-07-24 22:01:42
{{ abouts }}是一个查询集。下面的代码遍历查询集内的每个项目,从而创建一个列表。
<ul>
{% for about in abouts %}
<li>{{ about.description }}</li>
{% endfor %}
</ul>https://stackoverflow.com/questions/63074815
复制相似问题