1

首先我的设置:

  • Linux Mint 18.2
  • 百日草 0.20
  • Django 1.9.9
  • cookiecutter-django 1.9.9
  • Python 3.5.2

我已经使用 cookiecutter-django 从头开始​​创建了一个项目,使用版本 1.9.9,一旦在 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.

我怎样才能解决这个问题?

4

1 回答 1

0

通过加载用户模型的方式,我发现这是 Zinnia 上的一个“错误”。

在 zinnia/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()

并完美运行。

我正在尝试在干净的安装中对其进行测试。如果它有效,我会用它提出一个拉取请求。

于 2019-03-13T11:24:41.763 回答