UpdateView 问题:在 url 中传递的清理数据不在实例中

优比星

我的更新视图有问题,但我不知道为什么会这样。因此,当我尝试使用 UpdateView 更新对象时,我没有收到任何错误显示它不起作用并重新加载页面,而是将更改后的数据传递给 url :

"[11/Dec/2018 11:49:20] "GET /home/update/vacation/421?csrfmiddlewaretoken=Op55u8r2GG2uyDjIvW2rstfedeU646ZkrJsmUOC6824rRO5W5NTT4koNwe2if0auxt4koNwe2if0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2018

我试图覆盖 form_invalid 和 fom_valid 以了解发生了什么,但它没有打印任何内容

有谁知道为什么这不起作用?

views_class.py

class VacationUpdate(LoginRequiredMixin, UpdateView):
    login_url = 'login'
    redirect_field_name = 'redirect_to'
    form_class = VacationUpdateForm
    model = Vacation
    template_name = 'chiffrage/forms/vacation_update.html'
    pk_url_kwarg = 'vacation_id'

    def form_invalid(self, form):
        print(form.changed_data)

    def form_valid(self, form):
        print(form.data)
        vacation = form.save(commit=False)
        vacation.updated_by = self.request.user
        vacation.save()
        return super().form_valid(form)

    def get_success_url(self):
        return HttpResponseRedirect(reverse('marge_prix', args=(
                                                self.object.version_contrat.contrat.site.client.slug(),
                                                self.object.version_contrat.contrat.site.client.pk,
                                                self.object.version_contrat.contrat.site.slug(),
                                                self.object.version_contrat.contrat.site.pk,
                                                self.object.version_contrat.contrat.slug(),
                                                self.object.version_contrat.contrat.id,
                                                self.object.version_contrat.slug(),
                                                self.object.version_contrat.id)))

表格.py

class VacationUpdateForm(forms.ModelForm):
    class Meta:
        model = Vacation
        fields = ['poste_travail', 'taux_marge']

网址.py

path('update/vacation/<int:vacation_id>', views_class.VacationUpdate.as_view(), name='vacation_class_update'),

path('clients/<slug:client_name>,<int:client_id>/<slug:site_name>,<int:site_id>/<slug:contrat_slug>,<int:contrat_id>/<slug:version_slug>,<int:version_id>/prix', views.vacation_add,
     name='marge_prix'),

假期更新.html

{% extends 'base.html' %}
{% block title %} {{ request.user }}{% endblock %}
{% block ligne-titre %}{{ client }}{% endblock %}
{% block sans-div %}
<div class="main container-fluid col-8">

<form class="form-group">
    {% csrf_token%}
    <table class="table table-sm table-bordered">

    {{ form.as_table }}
    <tr>
        <td colspan="2"><input class="align-self-center btn btn-secondary " type="submit" value="Nouveau"></td>
    </tr>
    </table>
</form>
</div>
{% endblock %}
詹姆斯·赖特

您没有method适合您的表单设置。这意味着表单使用的是默认的GET提交方法

尝试更改vacation_update.html为:

{% extends 'base.html' %}
{% block title %} {{ request.user }}{% endblock %}
{% block ligne-titre %}{{ client }}{% endblock %}
{% block sans-div %}
<div class="main container-fluid col-8">

<form class="form-group" method="post">
    {% csrf_token%}
    <table class="table table-sm table-bordered">

    {{ form.as_table }}
    <tr>
        <td colspan="2"><input class="align-self-center btn btn-secondary " type="submit" value="Nouveau"></td>
    </tr>
    </table>
</form>
</div>
{% endblock %}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Django中的UpdateView问题

来自分类Dev

从Django UpdateView中的URL返回PK

来自分类Dev

访问UpdateView中的对象以传递pk以获得success_url

来自分类Dev

如何在Django中获取updateview的url参数?

来自分类Dev

R中的URL问题

来自分类Dev

URL拆分中的问题

来自分类Dev

foreach中url的问题

来自分类Dev

symfony 中的 url 问题

来自分类Dev

$ resource URL数据问题

来自分类Dev

使用UpdateView的success_url返回PagedFilteredTableView

来自分类Dev

curl的问题:URL中的括号

来自分类Dev

加密OKHttp中的URL问题

来自分类Dev

在angularjs的URL中删除#的问题

来自分类Dev

传递给其他 UpdateView 的 Django UpdateView 初始参数

来自分类Dev

从URL传递到URL时的Mcrypt问题

来自分类Dev

Django UpdateView 和 ChoiceField 问题。Django 1.11 蟒蛇 3.6

来自分类Dev

网址中没有pk的Django UpdateView

来自分类Dev

网址中没有pk的Django UpdateView

来自分类Dev

Django通用CreateView和UpdateView中的Modelformset

来自分类Dev

UpdateView中的自动更新子弹字段

来自分类Dev

Django中相同模型的UpdateView的不同模板

来自分类Dev

Django:在UpdateView中覆盖get_queryset()

来自分类Dev

网址中没有pk的Django UpdateView

来自分类Dev

无法在Django的UpdateView中更新投票日期

来自分类Dev

URL问题检索Yahoo Finance中的数据报价

来自分类Dev

Shopify:链接列表中的URL图像问题

来自分类Dev

Django URL中的单字符参数问题

来自分类Dev

Codeigniter URL中的双斜杠问题

来自分类Dev

.htaccess重写URL中遇到问题