如何对局部视图执行相同的操作?在
在视图.py在
class ViewProfile(generic.DetailView):
model = User
slug_field = 'username'
template_name = 'profile/profile_view.html'
def get_context_data(self, **kwargs):
ctx = super(ViewProfile, self).get_context_data(**kwargs)
ctx['profile'] = Profile.objects.all()
return ctx
简介_视图.html在
^{pr2}$我只需要将列表中的第一个显示为详细信息视图。有什么办法吗?在
在queryset上使用first() method
视图.py
简介_视图.html
^{pr2}$还可以使用order_by() method更改查询集的顺序。在
您已经给迭代变量指定了与迭代器相同的名称,只是使它们不同而已
相关问题 更多 >
编程相关推荐