【发布时间】:2013-05-12 18:20:56
【问题描述】:
是否可以在基于 Django 类的视图中使用装饰器 commit_manually?
【问题讨论】:
是否可以在基于 Django 类的视图中使用装饰器 commit_manually?
【问题讨论】:
与您使用 any other decorator in a class based view 的方式相同。
我个人喜欢在类视图上装饰dispatch 方法:
class ManualCommitView(SomeView):
@method_decorator(commit_manually)
def dispatch(self, *args, **kwargs):
return super(ManualCommitView, self).dispatch(*args, **kwargs)
但这只有在您计划重用视图时才值得,否则在 URLconf 中装饰视图会更容易。
【讨论】: