Skip to main content
 首页 » 编程设计

python之django 剥离/删除/清除值

2025年05月04日8qq号

我正在使用 django 1.6.7 和 python 2.7。

我正在尝试清除字段中符合条件的数据,然后再将值提交到数据库。

我一直在使用 strip,但这不再有效。搜索 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) 

我希望这对某人有帮助。