[英]Issue with users model in zinnia and cookiecutter-django integration
首先我的設置:
我使用cookiecutter-django從頭開始創建了一個項目,使用版本1.9.9,一旦在百日草文檔中,建議使用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.
我怎樣才能解決這個問題?
通過加載用戶模型,我發現這是百日草的“錯誤”。
在百日草/模型/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()
並完美運行。
我正在嘗試在全新安裝中對其進行測試。 如果有效,我將向其發出請求請求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.