为了账号安全,请及时绑定邮箱和手机立即绑定

Django 不使用 UpdateView 进行更新

Django 不使用 UpdateView 进行更新

12345678_0001 2021-09-14 20:49:33
我有这个视图来显示以前填充的数据,这些数据只填充在管理面板中:from .models import (Token,                     Sell,                     LogisticCost,                     IncomeCost,                     FinalPayment,                     CustomerServiceCost,                     Fatura)def product_list(request):    context = {'product_list': ProductList.objects.filter(client=request.user.id).all(),               'data_payment': Fatura.objects.all()}    return render(request, 'Clientes/list_products.html', context)这是更新这些值的视图:class UpdateProduct(UpdateView):    model = ProductList    context_object_name = 'product_list'    template_name = 'Clientes/update_product.html'    fields = ['name', 'description', 'cost_price', 'sell_price', 'ncm']我在更新页面中的表单是:<form method="post" action="{% url 'client:product_list' %}">    {% csrf_token %}    {{ form }}    <button class="btn btn-inverse" type="submit">Atualizar</button></form>我的更新页面按预期工作,显示与所选对象相关的每个值,但是当我提交表单时,模型没有改变。不更新值会发生什么?
查看完整描述

2 回答

?
神不在的星期二

TA贡献1963条经验 获得超6个赞

毕竟,我从表单中删除了操作并将变量添加success_url = reverse_lazy('client:product_list')到我的 UpdateView。那解决了问题。


查看完整回答
反对 回复 2021-09-14
  • 2 回答
  • 0 关注
  • 234 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号