Django NameError 名称“请求”未定义

Dic*_*mbo 0 python django django-views

出现错误 Django NameError 名称“请求”未定义。

我的 views.py

class ShiftCreateView(CreateView):
    fields = ('name', 'timein', 'timeout', 'desc')
    model = models.Shift

    def form_valid(self, form):
        self.object = form.save(commit=False)
        self.object.timein = request.POST.get("timein", "")
        self.object.timeout = request.POST.get("timeout", "")
        self.object.save()


        return super(ModelFormMixin, self).form_valid(form)
Run Code Online (Sandbox Code Playgroud)

Lem*_*eur 7

在 CBV 中,可以从对象获得请求self

self.object.timein = self.request.POST.get("timein", "")
self.object.timeout = self.request.POST.get("timeout", "")
Run Code Online (Sandbox Code Playgroud)