我的应用在本地运行时没有问题。但它发生在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。
感谢。
答案 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...
)