Python中文
首页
教程
问答
标签
搜索
登录
注册
Django格式的隐藏字段不在cleaned中
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我有这个表格:</p> <pre><code>class CollaboratorForm(forms.Form): user = forms.CharField(label="Username",max_length=100) canvas = forms.IntegerField(widget=forms.HiddenInput) .... def clean_user(self): user = self.cleaned_data['user'] canvas = self.cleaned_data['canvas'] </code></pre> <p>在我看来,我只是打电话给你</p> ^{pr2}$ <p>我得到了一个错误:</p> <pre><code>KeyError at /canvas/1/add-collaborator/ 'canvas' </code></pre> <p>根据firebug发布的值,它似乎并没有进入我的clean函数。我做错了吗?</p> <p>编辑:发布数据</p> <pre><code>canvas 1 csrfmiddlewaretoken 2cb73be791b32ca9a41566082c804312 user username </code></pre> <p>EDIT2:我也愿意接受一个答案,告诉我如何将主键发送到clean_user函数,其中主键是上面示例url中的/1/。视图中被调用的函数是:</p> <pre><code>def canvas_add_collaborator(request, pk): </code></pre> <p>所以我想把pk发送到clean_用户函数,它可以解决我的问题,不需要隐藏字段。</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>我发现字段声明中的顺序很重要,因此如果要在clean_user方法中访问cleaned_data['canvas'],必须首先在字段中声明canvas。我已经在模型中测试过了</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
在python3中使用Scipy pearsonr函数
4 回答
在Python3中使用scipy对多个lorentzian进行数据拟合
9 回答
在Python3中使用Script=argv
4 回答
在python3中使用selenium webdriver进行未解析的回溯
9 回答
在python3中使用selenium和phantomjs的网页截图之前如何等待?
1 回答
在Python3中使用Selenium和Requests模块从网页获取文件
3 回答
在python3中使用SIGINT终止函数
2 回答
在Python3中使用SIGTERM时,允许进程完成而不是中断
7 回答
在python3中使用smtplib发送XML内容
1 回答
在python3中使用socket库(RFCOMM模式)重新连接蓝牙设备?
5 回答
在python3中使用sounddevice和numpy编写wav文件
5 回答
在python3中使用Sqlalchemy插入MySQL查找类型错误的原因
10 回答
在python3中使用sqlite、pandas和sqlalchemy很难让rollback工作
4 回答
在python3中使用SQLite的FTS3/4
3 回答
在Python3中使用struct.calcsize()和len()有区别吗?
7 回答
在python3中使用substring函数时发生TypeError
3 回答
在Python3中使用Tkinter entry小部件写入串行设备
7 回答
在python3中使用tkinter时,如何在每次按下函数时获得运行该函数的按钮?
9 回答
在python3中使用tkinter的子帧
6 回答
在Python3中使用tryexcept块时,如何避免使用未初始化的变量?
2 回答