django添加管理类别错误

时间:2017-03-02 03:29:08

标签: django

# settings.py

MEDIA_URL = '/media/'
MEDIA_ROOT =os.path.join(BASE_DIR,'media/')


#urls.py outer

from django.conf.urls import url, include
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'', include('webapp.urls')),

]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL,
                          document_root = settings.MEDIA_ROOT)

#admin.py of webapp
from django.contrib import admin
from .models import Profile


class ProfileAdmin(admin.ModelAdmin):
    list_display = ['user', 'birthday', 'photo']

admin.site.register(Profile, ProfileAdmin)

#models.py of webapp

class Profile(models.Model):
    user = models.OneToOneField(settings.AUTH_USER_MODEL)
    birthday = models.DateField()
    photo=models.ImageField(upload_to='users/%Y/%m/%d',blank=True)

    def __str__(self):
        return 'Profile for user {}'.format(self.user.username)

完整错误追溯

Traceback (most recent call last):
  File "./manage.py", line 8, in <module>
    from django.core.management import execute_from_command_line
  File "/home/peterkim/PycharmProjects/bravepeach_web/.venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 13, in <module>
    from django.core.management.base import (
  File "/home/peterkim/PycharmProjects/bravepeach_web/.venv/lib/python3.5/site-packages/django/core/management/base.py", line 13, in <module>
    from django.core import checks
  File "/home/peterkim/PycharmProjects/bravepeach_web/.venv/lib/python3.5/site-packages/django/core/checks/__init__.py", line 11, in <module>
    import django.core.checks.caches  # NOQA isort:skip
  File "/home/peterkim/PycharmProjects/bravepeach_web/.venv/lib/python3.5/site-packages/django/core/checks/caches.py", line 14, in <module>
    @register(Tags.caches)
TypeError: register() missing 1 required positional argument: 'kwargs'

我无法弄清楚为什么会这样。请帮忙。提前谢谢!

1 个答案:

答案 0 :(得分:0)

尝试单独注册每个模型

admin.site.register(Profile)
admin.site.register(ProfileAdmin)