我有一个父视图和一个子视图。我想在子视图中覆盖一个自定义函数,如下所示:
我的网址:
path('<int:place_id>/add_images/', AddImages.as_view(), name="add-images"),
path('<int:place_id>/edit/images/', EditImages.as_view(), name="edit-images"),
# PARENT:
class AddImages(LoginRequiredMixin, View):
template_name = images/add_images.html
# HERE I GET THE CURRENT URL:
def next_url(self):
next_url = "?next={0}".format(self.request.path)
print("NEXT URL:" + str(next_url))
return next_url
# AND I USE IT HERE:
def post(self, request, **kwargs):
# ...
next_url = self.next_url()
data = {'next_url' : next_url }
return JsonResponse(data)
# CHILD:
class EditImages(AddImages):
"""
Inherits from ImagesView. overwrites template and next_url
"""
template_name = "images/edit_images.html"
def next_url(self):
next_url = "?next={0}".format(self.request.path)
print("CHILD URL2:" + str(next_url))
return next_url
我想覆盖父视图 next_url 并将其传递给 post()
目前输出只打印:“NEXT URL: ...”
我该如何解决这个问题?提前致谢