代码之家  ›  专栏  ›  技术社区  ›  Nameless

django中不存在模板错误

  •  1
  • Nameless  · 技术社区  · 9 年前

    {{ update_form }}
    

    part\u 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>
    

    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

    1 回复  |  直到 9 年前
        1
  •  0
  •   SandroM    9 年前

    你好像有打字错误 part_details.html part_detail.html