django - Django - ModelForm 忽略新字段并且不在模板中显示它
问题描述
我在生产服务器上的应用程序中有以下模型:
class FullPolicyForm(forms.ModelForm):
class Meta:
model = Policy
fields = ('name',)
# common info
name = forms.CharField(widget=forms.TextInput(attrs={'class':
'float-none', 'style':'width:140px;'}), required=True)
sdk_enabled = forms.BooleanField(required=False)
remote_config_time_window = forms.IntegerField()
#more fields exists here.....
在我的开发环境中,我添加了一个新字段:
group_name = forms.CharField(widget=forms.TextInput(attrs={'class': 'float-none', 'pattern':'^[a-zA-Z\d-_]*$', 'style':'width:140px;'}), required=False)
我也在我的模板中添加了该字段
<div class="fieldWrapper">
<label class="control-label col-sm-3 float-none">Group name:</label>
{{ form.group_name }}
<span class="label label-info" style="cursor: help;" data-toggle="popover-ex" data-placement="right"
title="{{ field_description.group_name.0 }}" data-content="{{ field_description.group_name.1 }}" footer="{{ field_description.group_name.2 }}">?</span>
</div>
我在开发环境中测试了代码,一切正常。然后我将代码提交到远程仓库,然后在我的生产环境中提取更改。然后当我打开网页时,除了新字段(group_name)之外,所有以前的表单字段都存在,只出现了标签和跨度元素。什么会导致 Django 忽略新的模型表单字段?
笔记:
我使用重新启动服务器
pkill -f runserver
,我也tried sudo systemctl restart nginx
我没有对我的实际模型进行任何更改,只是在模型表单中添加了新字段。
编辑:我在 AWS 上使用 nginx 和 uwsgi
解决方案
推荐阅读
- cognos-bi - 在交叉表中编辑“无价值” - Cognos Analytics 仪表板
- php - 通过 PHP 将 XML 转换为 CSV - 如何获取属性值?
- php - 将函数放在其中时,php中出现错误
- php - 如何将 php.ini 添加到 kubernetes yaml 中的 configmap
- reactjs - 尝试使用清单中的以下图标时出错
- database - 在 sonarqube 中备份和恢复
- android - Snapshot Listener 如何处理离线数据?
- c# - 在 C# 中更改为速记属性后使用模型反序列化时,值变为空
- angular9 - `Angular9` 中没有`$ rootScope`。可以使用什么?
- c# - 如何从 C# 中的图片中检测(以及稍后解析)二维码?