我正在使用CherryPy在Python中处理Web应用程序。我在页面上有一个表单,用于编辑用户配置文件,因此当您加载页面时,默认值会被填充。这使用Jinja2进行模板化,因此无论您是编辑还是创建配置文件,都会将变量传递给页面以告知它。CherryPy - 400错误,来自HTML表单的参数的多个值
<form method="post">
<span class="left">
<span id="prof-art" class="prof-art" style="background-image: url({{ '/assets/profile-art/'+(prof.prof_id|string)+'.jpg' if prof.prof_id else '/static/img/new-user.jpg' }});"></span>
<span class="prof-name"><input type="text" name="name" placeholder="Name" autocomplete="off" {{ 'value="'+prof.name+'"' if prof.name }}></span>
<span class="prof-loc"><input type="text" name="loc" placeholder="Location" autocomplete="off" {{ 'value="'+prof.location+'"' if prof.location }}></span>
<span class="prof-url">example.com/u/<input type="text" name="url" autocomplete="off" {{ 'value="'+prof.url+'"' if prof.url }}></span>
<span class="prof-bio"><textarea name="bio" placeholder="Add a description of yourself here. Markdown is supported." autocomplete="off">{{ prof.bio or '' }}</textarea></span>
<span class="prof-img"><input type="file" name="img" id="imgInp"></span>
</span>
<button type="submit" class="blue-btn a prof-save">
{% if editing %}<i class="fa fa-wrench"></i> Update
{% else %}<i class="fa fa-plus-square"></i> Create
{% endif %}</button>
</form>
提交时,代码将处理您提供的数据并保存或创建,具体取决于您是在编辑它还是创建您的配置文件。
但是,这并不重要,因为在我的代码被处理之前HTTPError发生了。
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/cherrypy/_cprequest.py", line 670, in respond
response.body = self.handler()
File "/Library/Python/2.7/site-packages/cherrypy/lib/encoding.py", line 217, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "/Library/Python/2.7/site-packages/cherrypy/_cpdispatch.py", line 67, in __call__
raise sys.exc_info()[1]
HTTPError: (400, 'Multiple values for parameters: url')
这是怎么回事?为什么只是URL字段这样做?即使我从模板中删除了值标签,它也会执行此操作。我找不到任何可能导致此问题的东西 - 表单中有一个网址字段,为什么它认为有2个?它似乎在提交时发生,因为在弹出错误之前,CherryPy服务器中甚至没有运行。
更新:我写了一个快速的Python Web服务器,打印出我发送请求中的所有数据。通过将action属性更改为该服务器的地址,我可以检查表单传递的POST变量。原来,它甚至可能不是HTML格式的错,而是CherryPy的。
POST Variables: {'url': 'dfghdfgdf', 'loc': 'fghjdfg', 'name': 'dfghdfgdf', 'btc': '', 'bio': 'srffghmn+dfghdfgh'}
处理该请求的方法签名是什么? – cyraxjoe
你是什么意思?如果它是
我的意思是'def METHOD(self,a,b,* c,** d)' – cyraxjoe