我正在使用Django 1.6.7和python 2.7。

我试图在将值提交到数据库之前清除字段中的数据(如果它符合条件)。

我一直在使用脱衣舞,但这不再起作用。搜索django文档后,我找不到解决方案。

这是我的forms.py文件中的代码,其中strip()不起作用:

        if atype_config.LocalityDisplay:
            def clean_address_locality(self):
                value = self.cleaned_data['address_locality']
                return value.strip()

最佳答案

答案不是去用户区。使用pop()代替。

这是代码:

if not atype_config.LocalityDisplay:
    self.cleaned_data.pop('address_locality', None)


我希望这对某人有帮助。

关于python - django条/删除/清除值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26623810/

10-12 12:39
查看更多