路径如下:
admin.py的代码:
from django.contrib import admin from sign.models import Event,Guest # Register your models here. class EventAdmin(admin.ModelAdmin): list_display = ['id','name','status','address','start_time'] class GuestAdmin(admin.ModelAdmin): list_display = ['realname','phone','email','sign','create_time','event'] admin.site.register(Event.EventAdmin) admin.site.register(Guest.GuestAdmin)
错误:
解决办法:
from django.contrib import admin from .models import Event,Guest # Register your models here. class EventAdmin(admin.ModelAdmin): list_display = ['id', 'name', 'status', 'address', 'start_time'] class GuestAdmin(admin.ModelAdmin): list_display = ['realname', 'phone', 'email', 'sign', 'create_time', 'event'] admin.site.register(Event,EventAdmin) admin.site.register(Guest,GuestAdmin)
原因分析:
1:导包路径错误,同一路径下用 from .models import *
2: 逗号写成点号。 应该是 admin.site.register(Event,EventAdmin) admin.site.register(Guest,GuestAdmin)