在后端模板上显示确认消息(python/Django)

2024-05-15 01:55:10 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我有JSONResponseMixin View,这个视图的主要功能是在用户单击GUI中的confirms之后将状态更改为confirmed。我想显示一个弹出窗口,说明它已确认。我怎么能从django做到呢视图.py?你知道吗

以下是我的观点

class ConfirmView(JSONResponseMixin, View):

    def post(self, request, *args, **kwargs):
        status = 'error'
        msg = "this is from me"
        post_body = json.loads(self.request.body)
        fab_value = post_body['fab']
        mast_value = post_body['mast']
        comment = post_body.get('comment')

        try:
           object = Forecast.objects.get(fab=fab_value, mast=mast_value, type='XC')
        except ObjectDoesNotExist:
            object = []
        else:
            if object.status == 'notified(created)' or 'notified(updated)':
                object.status = 'confirmed'
                object.comment = second_po_comment
                object.confirm = self.request.user
                object.modified_by =User.objects.get(username=self.request.user.username)
                object.save()

        return self.render_json_response(dict(status=status, msg=msg))

Tags: selfview视图getobjectvaluerequeststatus

热门问题