【发布时间】:2021-12-15 05:57:30
【问题描述】:
问题是model description_text的文本没有显示出来。对不起我的英语。
这是html代码
{% for description_text in context_object_name %}
<h1 class="description"><a href="/Homepage/{{ goods.id }}/">{{goods.description_text}}</a></h1>
{% endfor %}
这是views.py的代码
class IndexView(generic.ListView):
template_name = 'Homepage/index.html'
model = Goods
context_object_name = 'goods.description_text'
def description(self):
return self.description_text
def price(self):
return self.price_text
def get_queryset(self):
"""Return the last five published questions."""
return Question.objects.order_by('-pub_date')[:5]
这是models.py的代码
class Goods(models.Model):
description_text = models.CharField(max_length=200)
price_text = models.CharField(max_length=200)
def __str__(self):
return self.description_text
def __str__(self):
return self.price_text
这是admin.py的代码
from django.contrib import admin
from .models import Good
from .models import Question
admin.site.register(Good)
admin.site.register(Question)
class Good(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['description_text']}),
(None, {'fields': ['price_text']}),
]
【问题讨论】:
-
你好 Licrencie 欢迎来到论坛你应该考虑这些代码错误
标签: python html django django-models django-views