什么时候在django中调用get_context_data(...)?

时间:2017-07-09 02:14:16

标签: ajax django

我正在使用Django中的类Updateview来重新编写url

        $('.edit_btn').on('click',pop_up);
          function pop_up() {

           $.ajax({
             url: url of stock_update_view,
             data: {
             },
             dataType: 'json',
             success: function ( ) {
             alert("success");
             }
           });    
        }

,UpdateView类是:

class stock_update_view(UpdateView):
    model = part_stock
    fields = ['part_id','entry_date','supplier','amount','remaining']
    success_url = reverse_lazy('parts:part_list')
    template_name = 'part_detail.html'

    def get_context_data(self, **kwargs):
        context = super(stock_update_view, self).get_context_data(**kwargs)
        context['update_form'] = context.get('form')
        return context

    def get(self, request, *args, **kwargs):
        username = request.GET.get('username', None)
        data = {

        }
       return JsonResponse(data)

我正在调用stock_view_updat以获取上下文['update_form']将调用它虽然ajax将调用get_context_data(...)并且我能够在我的模板中使用'update_form'吗?

0 个答案:

没有答案