Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在flask中的表单中选择一些字段_Python_Python 3.x_Forms_Flask_Postman - Fatal编程技术网

Python 如何在flask中的表单中选择一些字段

Python 如何在flask中的表单中选择一些字段,python,python-3.x,forms,flask,postman,Python,Python 3.x,Forms,Flask,Postman,我需要知道如何处理表单中的可选字段。这是该函数的完整代码 def post(self): print(request.headers['Content-Type']) email = request.form.get('email') title = request.form.get('title') os_type=request.form.get('os_type') device_type=request.form.get('device_t

我需要知道如何处理表单中的可选字段。这是该函数的完整代码

    def post(self):
    print(request.headers['Content-Type'])
    email = request.form.get('email')
    title = request.form.get('title')
    os_type=request.form.get('os_type')
    device_type=request.form.get('device_type')
    message=request.form.get('message')
    file = request.files.get('file')
    target_url = request.form.get('target_url')
    print(email)
    if email == None and email == '':
        st="email is required"
        data=error_call(st)
        return(data),400,{'Content-Type': 'application/json'}
    else:
        return (email)
        if title== None and title == '':
            st="title is required"
            data=error_call(st)
            return(data),400,{'Content-Type': 'application/json'}
        else:
            if message==None and message== "":
                return(error_call("message is requied")),400,{'Content-Type': 'application/json'}
            else:
                date=datetime.now()
                if file:
                    a=20
                    print(a)
                    if a>20000:
                        return(error_call("sixe of file exceeded"))
                    else:

                        if file.filename == '':
                            return "no file"
                        if file and allowed_file(file.filename):
                            file.filename = title
                            filename = secure_filename(file.filename)
                            file.save(os.path.join('images/push_uploads', filename))
                            image_url='http://127.0.0.1:5000/'+'images/push_uploads'+'/'+filename

                            data_message = {
                            "to":"dkmdi",
                            "content_available":"true",
                            "mutable_content":"true",
                            "data":{
                           "mediaUrl":image_url
                            },
                            "notification":{
                                "body" : "mmsiadk",
                                "type" :"message_type",
                                "sound" :"default"

                            }

                            }
                            print(image_url)
                            registration_id ="cVFt1vC16j8:APA91bEhRS1mvPn3NZGODC4zoGjcsfmhV59cpqRd_i0Rmh1fwjgIj8bdxPlLoxlJkS5HBtEeFuE-ZSt3Uc6S0RwkT9UDqTdwYOiJa0gByNc09hZT1iVFSMM2BuuEXoLg5cARmOe73S5c"
                            message_body = title
                            #result = push_service.notify_single_device(registration_id=registration_id, message_body=message_body,data_message=data_message)
                            #print(result)
当我没有使用邮递员发送一些字段时,我得到了错误

"message": "The browser (or proxy) sent a request that this server could not understand."}

因此,我不需要知道如何处理python格式的可选字段

请尝试以下示例:

title = request.form.get('title')

如果未提供“标题”字段,则不会引发异常。

如果不提供值,当然也不会获得值当我未提供电子邮件时,我尝试了此代码。如果电子邮件==无且电子邮件='':st=“需要电子邮件”数据=错误\u调用(st)返回(数据),则我不会进入循环,400,{'Content-Type':'application/json'}对不起,我不明白。也许你可以编辑你的问题来扩展你的问题