【问题标题】:ImportError on Heroku django-registration-reduxHeroku django-registration-redux 上的 ImportError
【发布时间】:2016-10-01 12:34:54
【问题描述】:

我的应用在本地运行时没有问题。但它发生在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 时,这没什么错误。

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

谢谢。

【问题讨论】:

    标签: python django heroku django-registration


    【解决方案1】:

    您是否按照此处的指南 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...
    )
    

    【讨论】:

    • 是的,我做到了。我的应用程序在本地运行没有问题......我仍然不知道这个问题......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-24
    • 1970-01-01
    • 2012-02-21
    • 1970-01-01
    • 2016-07-06
    • 1970-01-01
    相关资源
    最近更新 更多