我知道這是由於視圖的代碼路徑不返回HttpResponse
而引起的,顯然。我是django的新手,所以這可能是完全錯誤的。FormView:查看沒有返回HttpResponse對象
這裏是FormView代碼。我是否需要覆蓋render_to_response
?
class AddAdvertView(FormView):
form_class = NewAdForm
def get(self, *args, **kwargs):
self.campaign = get_object_or_404(Campaign, id__exact = self.kwargs['campaign_id'])
def post(self, request, *args, **kwargs):
pass
def get_form(self, form_class):
return form_class(initial = {}, campaign = self.campaign)
def get_success_url(self):
return self.request.META.get('HTTP_REFERER', None)
def form_valid(self, form):
return HttpResponse('form valid')
def form_invalid(self, form):
return HttpResponse('form invalid')
感謝您的幫助。是的,我注意到基於類的視圖缺乏文檔。令人沮喪的是,這樣一個很好的解決方案沒有像這樣記錄下來。 –