- setting.py 配置文件打开后台模块:django.contrib.admin,django.contrib.auth,django.contrib.contenttypes,django.contrib.sessions,django.contrib.sites
INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', # Uncomment the next line to enable the admin: 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', 'artcle' )
- urls.py 路由配置文件,取消注释:from django.contrib import admin,admin.autodiscover(), url(r'^admin/', include(admin.site.urls)),
from django.conf.urls import patterns, include, url # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', # Examples: url(r'^$', 'blogsapce.views.home', name='home'), # url(r'^blogsapce/', include('blogsapce.foo.urls')), # Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), )
- 模块下新建admin.py管理模块注册文件
from django.contrib import admin from artcle.models import DrArtcle, DrCategory class DrArtcleAdmin(admin.ModelAdmin): list_display = ('art_title','art_id', 'art_author', 'art_summary', 'inputtime') ordering = ('-inputtime',) search_fields = ('art_title',) admin.site.register(DrArtcle, DrArtcleAdmin) class DrCategoryAdmin(admin.ModelAdmin): pass admin.site.register(DrCategory, DrCategoryAdmin)
- 运行,进入后台可见
Django-- admin后台管理模块的使用
最新推荐文章于 2023-02-08 09:46:01 发布