首页 > 解决方案 > 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

标签: django

解决方案


推荐阅读