首先我的设置:
我使用版本1.9.9从头开始创建了一个带有cookiecutter-django的项目,曾经在zinnia docs中建议使用django< 2.0。我只是:
git checkout 1.9.9
我按照文档操作,项目运行正常。然而,添加百日草之后,我无法迁移。这是我的file config/settings/common.py
THIRD_PARTY_APPS = (
'crispy_forms', # Form layouts
'allauth', # registration
'allauth.account', # registration
'allauth.socialaccount', # registration
'mptt',
'tagging',
'zinnia',
)
TEMPLATES = [
{
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
'BACKEND': 'django.template.backends.django.DjangoTemplates',
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
'DIRS': [
str(APPS_DIR.path('templates')),
],
'OPTIONS': {
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
'debug': DEBUG,
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
# https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
# Your stuff: custom template context processors go here
'zinnia.context_processors.version', # Optional
],
},
},
]
和confi/urls.py
urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='pages/home.html'), name='home'),
url(r'^about/$', TemplateView.as_view(template_name='pages/about.html'), name='about'),
# Django Admin, use {% url 'admin:index' %}
url(settings.ADMIN_URL, include(admin.site.urls)),
# User management
url(r'^users/', include('rmining.users.urls', namespace='users')),
url(r'^accounts/', include('allauth.urls')),
# Your stuff: custom urls includes go here
url(r'^weblog/', include('zinnia.urls')),
url(r'^comments/', include('django_comments.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
当我运行python manage.py migrate
时,我收到以下错误:
"Model '%s.%s' not registered." % (app_label, model_name))
LookupError: Model 'users.User' not registered.
我该如何解决这个问题?
答案 0 :(得分:0)
通过加载用户模型,我发现这是百日草的“错误”。
在百日草/models/author.py中:
def safe_get_user_model():
"""
Safe loading of the User model, customized or not.
"""
user_app, user_model = settings.AUTH_USER_MODEL.split('.')
return apps.get_registered_model(user_app, user_model)
我将其更改为:
[...]
from django.contrib.auth import get_user_model
[...]
def safe_get_user_model():
"""
Safe loading of the User model, customized or not.
"""
# user_app, user_model = settings.AUTH_USER_MODEL.split('.')
# return apps.get_registered_model(user_app, user_model)
return get_user_model()
并且运行完美。
我正在尝试在全新安装中对其进行测试。如果可行,我将向其发出请求请求。