Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.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 访问request.POST时出现KeyError_Python_Django_Django Forms - Fatal编程技术网

Python 访问request.POST时出现KeyError

Python 访问request.POST时出现KeyError,python,django,django-forms,Python,Django,Django Forms,我在python中发现了关键错误 像这样的错误 KeyError at /python_tutor/ 'user_script' 代码是 import web_exec def tutor(request): print "Inisde tutor", request.method print "POST =", request.POST if request.method == "POST" : print "Inside Post"

我在python中发现了关键错误

像这样的错误

KeyError at /python_tutor/
'user_script'
代码是

import web_exec
def tutor(request):
    print "Inisde tutor", request.method
    print "POST =", request.POST
    if request.method == "POST" :
        print "Inside Post"
        print "My Script =", request.POST["user_script"]
        mycode = request.POST["user_script"]
        exec mycode 
    web_exec('mycode')
请为我提供解决方案?

这意味着字典中不存在密钥(
user\u script
)(
request.POST
);这表明它没有被提交。尝试:

if 'user_script' in request.POST:
    print "My Script =", request.POST["user_script"]
    mycode = request.POST["user_script"]

mycode=request.POST.get('user\u script',None)
exec mycode
'instancemethod'对象不可订阅