【发布时间】:2020-03-09 04:19:34
【问题描述】:
如何修复列表视图在 Django 中不显示!
当我看到 html file 中没有显示数据时,我在基于类的视图中添加了列表视图
这是我的 views.py
class Buy_List_View(ListView):
model = user_buy
template_name = 'index.html'
这是我的 models.py
class user_buy(models.Model):
users = models.ForeignKey(user_register_model,on_delete=models.CASCADE)
payment_method = models.CharField(max_length=500)
price = models.IntegerField()
limits = models.IntegerField()
这是我的 index.html
{% for buy in user_buy_list %}
<tr>
<td><a href="#">{{ buy.users }}</a></td>
<td>{{ buy.payment_method }}</td>
<td>{{ buy.price }}</td>
<td>{{ buy.limits }}</td>
</tr>
{% endfor %}
这是我的 urls.py
from . import views
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('', views.index,name='index'),
path('accounts/signup/', views.user_reg,name='register'),
path('profile/<username>', views.user_profile, name='user_profile'),
path('buy/form/seller',views.Buy_List_View.as_view(),name='buy')
]
【问题讨论】:
-
在您的模板设置中是否添加了 'DIRS': [os.path.join(BASE_DIR, 'templates')],
-
对不起,我写错了网址
-
为什么你的模型是小写的?
标签: django django-models django-templates django-views django-class-based-views