Heroku django-registration-redux上的ImportError

时间:2016-06-01 23:49:54

标签: python django heroku django-registration

我的应用在本地运行时没有问题。但它发生在heroku上。我成功将我的应用程序部署到了heroku但是当我打开它时(我的DEBUG仍然TRUE),我ImportError No module named forms来自from registration.forms import RegistrationFormUniqueEmail。我很困惑,因为当我开始heroku run python manage.py shell并执行导入from registration.forms import RegistrationFormUniqueEmail时,没有任何错误。

enter image description here

urls.py

from myapp.forms import CustomRegistrationForm
from registration.backends.default.views import RegistrationView

urlpatterns = [
     url(r'^register/$', logout_required(RegistrationView.as_view(form_class=CustomRegistrationForm)), name='registration_register'),
     url(r'^', include('registration.backends.default.urls')),
]

的myapp / forms.py

from registration.forms import RegistrationFormUniqueEmail
from .validators import ForbiddenUsernamesValidator

class CustomRegistrationForm(RegistrationFormUniqueEmail):
    def __init__(self, *args, **kwargs):
        super(CustomRegistrationForm, self).__init__(*args, **kwargs)
        self.fields['username'].validators.append(ForbiddenUsernamesValidator)

的myapp / validators.py

from django.contrib.auth.models import User
from django.core.exceptions import ValidationError

def ForbiddenUsernamesValidator(value):
    forbidden_usernames = ['admin', 'settings', 'news', 'about', 'help', '........']
    if value.lower() in forbidden_usernames:
        raise ValidationError('This username is forbidden.')
    if len(value) < 4:
        raise ValidationError('Username must have at least 4 characters.')

这是我的应用here

感谢。

1 个答案:

答案 0 :(得分:0)

您是否按照此处的指南http://django-registration-redux.readthedocs.io/en/latest/quickstart.html安装了django-registration-redux?特别是这部分:

INSTALLED_APPS = (
    'django.contrib.sites',
    'registration', #should be immediately above 'django.contrib.auth'
    'django.contrib.auth',
    # ...other installed applications...
)