【问题标题】:Django admin page written text is not displaying on web pageDjango 管理页面书面文本未显示在网页上
【发布时间】:2020-07-24 13:43:08
【问题描述】:

忽略标题。我在管理页面上显示写入和保存的文本时遇到问题。 我只是创建名称为 about 的新应用程序。使用命令 python manage.py startapp 关于 以下所有文件都在这个应用程序中。

模型.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.title

admin.py

from django.contrib import admin
    from .models import About
    # Register your models here.
    admin.site.register(About)
    # Register your models here

views.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'),
]

关于.html

 <p style="color: white;">{{ abouts.discription }}</p>

问题是在描述里面写的文字没有显示在 about.html 页面上。请帮帮我。

【问题讨论】:

    标签: python django django-models django-views django-admin


    【解决方案1】:

    {{ abouts }} 是一个查询集。以下代码遍历查询集中的每个项目,从而创建一个列表。

        <ul>
            {% for about in abouts %}
                <li>{{ about.description }}</li>
            {% endfor %}
        </ul>
    

    【讨论】:

      猜你喜欢
      • 2011-05-09
      • 2017-06-21
      • 2013-07-09
      • 2023-03-04
      • 1970-01-01
      • 2019-03-08
      • 1970-01-01
      • 1970-01-01
      • 2018-11-13
      相关资源
      最近更新 更多