0
# 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)
完整的錯誤回溯Django的加入管理類錯誤
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'
我想不通爲什麼會這樣。請幫忙。先謝謝你!
你可以嘗試做從webapp.models一個完全合格的進口''導入Profile'',看看是否有幫助。 –