2017-07-10 7 views
1

part_stock_form.htmlテンプレートはジャンゴ

{{ update_form }} 

part_detail.html

<div> 
<form id="update_form" action="" method="post"> 
    {% csrf_token %} 
    <div id="my_form"> 
     {% if update_form %} 
      {{ update_form }} 
     {% else %} 
      {% include 'part_stock_form.html' %} 
     {% endif %} 
    </div> 
    <input type="submit" id="btn_stock_update" style="display: none;"> 
</form> 
</div> 
    $(function() { 

    $('.edit_btn').on('click',pop_up); 
    function pop_up() { 
     var update_url = url to update stock; 
     $('#update_form').attr('action',update_url); 
     $("#my_form").load(update_url,function() { 
      $("#btn_stock_update").show(); 
     }); 
    }); 
</script> 

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_stock_form.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 form_invalid(self, form): 
     print("form is invalid") 
     return render(self.request, 'part_details.html', {'update_form': form}) 

フォームが有効であるとき、それは正常に動作しますが、フォームが無効な場合、エラーが error image

+0

あるべきときにpart_details.htmlでタイプミスを持っているようです'part_stock_form.html'は常駐していますか?対応するアプリの 'templates'ディレクトリにありますか? – zaidfazil

+3

テンプレート名 'part_detail.html'または' part_details.html'とは何でしょうか、おそらくあなたは誤って表示されています。 – neverwalkaloner

答えて

0

を得ていることは、それはあなただpart_detail.html

関連する問題