django - 如何修复列表视图未在 Django 中显示
问题描述
如何修复列表视图未在 Django 中显示!
当我看到它没有显示数据时,我在基于类的视图中添加列表视图html file
我很累要修复你能帮帮我吗!
这是我的意见.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')
]
解决方案
我的 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')
]
至此
from . import views
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('', views.Buy_List_View.as_view(),name='index'),
path('accounts/signup/', views.user_reg,name='register'),
path('profile/<username>', views.user_profile, name='user_profile'),
]
因为我想显示在主页而不是这个页面!
推荐阅读
- python - 无法在 matplotlib 中设置 plt.xticks
- css - 即使使用旧前缀,Flex 属性在 IE 10 中也不起作用
- python - 在 numpy 中从 3d 获取特定的 2d 数组
- angular - 如何使用 videogular2 播放本地视频文件
- python - 是否可以为参数化生成输入?
- c - C Realloc 错误 - 结构中的动态数组
- quanteda - 如何将新的文本数据转换为预定义的 dfm?
- python - Python 'int' 对象在 For 循环中不可调用
- javascript - 如何将 cookie 与数组和 ajax 一起使用?
- java - 使用 eclipse 处理,无法运行 java 应用程序