Python VariableDoesNotExist:键[helper]的查找失败

Python VariableDoesNotExist:键[helper]的查找失败,python,django,postgresql,amazon-ec2,Python,Django,Postgresql,Amazon Ec2,为了让用户注册我的网站,注册表格需要电子邮件、实际地址、邮政编码和密码。我有两种不同的方法来运行我的应用程序——使用dev_manage.py(使用SQLite DB在本地主机上运行应用程序)和manage.py(托管在EC2实例上并使用PostgreSQL DB) 问题是,当我在本地主机上时,注册表单工作得很好,它在SQLite数据库中适当地存储电子邮件、地址、邮政编码和密码。然而,在该应用程序的实时EC2版本上,我使用crispy_forms helper时出现了一个VariableDoes

为了让用户注册我的网站,注册表格需要电子邮件、实际地址、邮政编码和密码。我有两种不同的方法来运行我的应用程序——使用dev_manage.py(使用SQLite DB在本地主机上运行应用程序)和manage.py(托管在EC2实例上并使用PostgreSQL DB)

问题是,当我在本地主机上时,注册表单工作得很好,它在SQLite数据库中适当地存储电子邮件、地址、邮政编码和密码。然而,在该应用程序的实时EC2版本上,我使用crispy_forms helper时出现了一个VariableDoesNotExist错误,出于某种原因,它试图只需要电子邮件和密码。另一方面,helper布局试图强制提供电子邮件、地址、邮政编码和密码。此外,如果我从模板标记中删除“helper”,那么本地主机注册表单仍然要求提供电子邮件、地址、邮政编码和密码,而EC2注册表单不再向我提供VariableDoesNotExist错误,而是只要求提供电子邮件和密码

有趣的是,dev.py和settings.py之间的唯一区别是每个版本使用的数据库:

dev.py(在dev_manage.py中调用):

settings.py(在manage.py中调用):

此外,我还删除了模式,删除了所有迁移,并重新迁移——基本上从零开始。必要的表和列已经存在,模式看起来正确,并且我已连接到PostgreSQL数据库

如果这些有帮助的话

注册.表格.py

from __future__ import unicode_literals


from django import forms
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.forms import UserCreationForm
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Layout, Field

from .users import UserModel, UsernameField

User = UserModel()


class RegistrationForm(UserCreationForm):
    """
    Form for registering a new user account.

    Validates that the requested username is not already in use, and
    requires the password to be entered twice to catch typos.

    Subclasses should feel free to add any additional validation they
    need, but should avoid defining a ``save()`` method -- the actual
    saving of collected user data is delegated to the active
    registration backend.

    """
    email = forms.EmailField(required=True, label='E-mail')
    address = forms.CharField(required=True, label='Street Address')
    zip_code = forms.CharField(required=True, label='Zip Code')

    class Meta:
        model = User
        fields = ('email', 'address', 'zip_code', 'password1', 'password2')

    def __init__(self, *args, **kwargs):
        super(RegistrationForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_show_labels = False
        self.helper.form_id = 'id-exampleForm'
        self.helper.form_class = 'blueForms'
        self.helper.form_method = 'post'
        self.helper.form_action = 'submit_survey'
        self.helper.add_input(Submit('submit', 'Create Account', css_class='btn btn-lg btn-primary'))

        self.helper.layout = Layout(
            Field('email', placeholder='E-mail'),
            Field('address', placeholder='Street Address'),
            Field('zip_code', placeholder='Zip Code'),
            Field('password1', placeholder='Password'),
            Field('password2', placeholder='Confirm Password'),
        )
from django.conf import settings

from .compat import get_model

try:
    from django.contrib.auth import get_user_model
    UserModel = get_user_model
except ImportError:
    UserModel = lambda: get_model('auth', 'User')


def UserModelString():
    try:
        return settings.AUTH_USER_MODEL
    except AttributeError:
        return 'auth.User'

def UsernameField():
    return getattr(UserModel(), 'USERNAME_FIELD', 'email')
注册.users.py

from __future__ import unicode_literals


from django import forms
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.forms import UserCreationForm
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Layout, Field

from .users import UserModel, UsernameField

User = UserModel()


class RegistrationForm(UserCreationForm):
    """
    Form for registering a new user account.

    Validates that the requested username is not already in use, and
    requires the password to be entered twice to catch typos.

    Subclasses should feel free to add any additional validation they
    need, but should avoid defining a ``save()`` method -- the actual
    saving of collected user data is delegated to the active
    registration backend.

    """
    email = forms.EmailField(required=True, label='E-mail')
    address = forms.CharField(required=True, label='Street Address')
    zip_code = forms.CharField(required=True, label='Zip Code')

    class Meta:
        model = User
        fields = ('email', 'address', 'zip_code', 'password1', 'password2')

    def __init__(self, *args, **kwargs):
        super(RegistrationForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_show_labels = False
        self.helper.form_id = 'id-exampleForm'
        self.helper.form_class = 'blueForms'
        self.helper.form_method = 'post'
        self.helper.form_action = 'submit_survey'
        self.helper.add_input(Submit('submit', 'Create Account', css_class='btn btn-lg btn-primary'))

        self.helper.layout = Layout(
            Field('email', placeholder='E-mail'),
            Field('address', placeholder='Street Address'),
            Field('zip_code', placeholder='Zip Code'),
            Field('password1', placeholder='Password'),
            Field('password2', placeholder='Confirm Password'),
        )
from django.conf import settings

from .compat import get_model

try:
    from django.contrib.auth import get_user_model
    UserModel = get_user_model
except ImportError:
    UserModel = lambda: get_model('auth', 'User')


def UserModelString():
    try:
        return settings.AUTH_USER_MODEL
    except AttributeError:
        return 'auth.User'

def UsernameField():
    return getattr(UserModel(), 'USERNAME_FIELD', 'email')

我完全被难住了。如何在本地主机上,而不是在我的EC2实例上,一切都能完全按照预期工作?我是否忘记或错过了某一步?另外,请告诉我是否有其他代码片段有助于故障排除。

经过几天的仔细检查,我刚刚发现了根本原因。我安装了django registration redux,通过pip卸载django registration redux解决了这个问题。我不完全确定这会导致问题的背后的技术原因,但同样的问题也影响了我构建的其他应用程序