我可以使用 Froala 上传图像,但找不到获取随响应发送的“pk”参数的方法。imageInsert 回调看起来没什么用。如何使用 ImageUpload 的真正回调?这是我在 django 中的代码:
class ArticleImageUploadView(CreateView):
form_class = ArticleUploadImageForm
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(ArticleImageUploadView, self).dispatch(*args, **kwargs)
def form_invalid(self, form):
return HttpResponse(json.dumps({'error':_('There was a problem processing your image. Please try again')}), content_type="application/json")
def form_valid(self, form):
#image = form.save(commit=False)
article_image = form.save(commit=False)
if "article_id" in self.request.POST:
article_image.article_id = self.request.POST.get("article_id")
article_image.save()
return HttpResponse(json.dumps({'link':article_image.image.url,'pk':article_image.pk}), content_type="application/json")