• 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)



  • 相关阅读:
    CMDB表结构设计
    mysql数据库密码
    web之提取状态码
    ELK的启动脚本
    ELK的轻量级搭建使用
    liunx安装JDK
    liunx的urandom生成随机字符
    vim快捷键
    升级系统的python程序
    Mysql的进阶小记
  • 原文地址:https://www.cnblogs.com/huny/p/13167979.html
Copyright © 2020-2023  润新知