【发布时间】:2020-08-31 14:10:58
【问题描述】:
我有一个看法:
class ProductList(SingleTableView):
model = Product
template_name = "app/product_list.html"
table_class = ProductTable
每一行都有一个应该执行function()的按钮:
class ButtonColumn(tables2.Column):
empty_values = list()
def render(self, value, record):
return mark_safe(f"""<a href="/link/{record.id}/"><button class="btn btn-info">link</button></a>""")
这个ButtonColumn 提供了一个按钮,一旦被点击:
path("link/<int:pk>", views.LinkView.as_view(), name="link"),
以及对应的视图:
class LinkView(TemplateView):
model = Product
template_name = "app/product_list.html"
def get_success_url(self):
return reverse_lazy('product-list')
def get_context_data(self, **kwargs):
context = super(LinkView, self).get_context_data(**kwargs)
function[kwargs] # <------------------
context["table"] = Product.objects.all()
return(context)
我的问题在于 Linkview - 我希望它使用一些 URL 传输参数执行 function 并返回到前一页 (app/product_list.html)。我怎样才能做到这一点?
【问题讨论】:
标签: django django-views django-tables2