Django踩坑记录3

路径如下:

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)



posted @ 2020-06-20 11:22  Harry_666  阅读(160)  评论(0编辑  收藏  举报