1.在xadmin.py,GlobalSettings中自定义菜单
2.自定义视图函数,并获取原来的菜单等一下信息(主要是为了用xadmin的模板),具体的自己看xadmin源码
3.在adminx.py中注册路由
4.html继承。
例:
xadmin.py:
class GlobalSettings(object):
site_title = "后台"
site_footer = "xxxx"
# menu_style = "accordion"
def get_site_menu(self):
return (
{'title': '新功能',
'menus': (
{
'title': '新功能',
'url': '/xadmin/xxxxview/',
},
)
},
)
# 调用原来model的话
def get_site_menu(self):
return (
{'title': 'ERP管理系统',
'perm': self.get_model_perm(models.ZVipbalance, 'view'),
'menus': (
{
'title': '新',
'url': '/admin/test_view/',
# 'perm': self.get_model_perm(ZVipbalanceList, 'view'),
},
)
},
)
views.py:
class TestView(CommAdminView):
def get(self, request):
context = super().get_context()
title = "会员延期"
# context["breadcrumbs"].append({'url': '/cwyadmin/', 'title': title})
context["title"] = title
return render(request, 'ERPSystem/t.html', context) #主目录的 template下的 html文件
# 调用本地文件进行展示
class LogView(CommAdminView):
def get(self, request):
context = super().get_context()
readfilecontent1 = []
readfilecontent2 = []
list = os.listdir('log')
path_last1 = ''
path_last2 = ''
last_time = ''
for i in range(0, len(list)):
if re.match(r'log',list[i]):
path = os.path.join('log', list[i])
if last_time == '' :
last_time = os.path.getmtime(path)
path_last1 = path
elif last_time < os.path.getmtime(path):
# path_last2 = path_last1
path_last1 = path
with open(path_last1, "r", encoding='gb2312') as f:
for line in f:
readfilecontent1.insert(0, line)
if path_last2 != '':
with open(path_last2, "r", encoding='gb2312') as f:
for line in f:
readfilecontent2.insert(0, line)
else:
path_last2 = 'no more'
context["title1"] = path_last1
context["title2"] = path_last2
context["context1"] = readfilecontent1
context["context2"] = readfilecontent2
return render(request, 'log.html', context)
xadmin.py:
import xadmin
from .views import TestView
xadmin.site.register_view(r'test_view/$', TestView, name='for_test'):
html:
1 {% extends 'xadmin/base_site.html' %} 2 {# 例 展示本地文件内容#} 3 {% block nav_form %} 4 <h3>{{ title1 }}</h3> 5 {% for i in context1 %} 6 <p>{{ i }}</p> 7 {% endfor %} 8 <h3>{{ title2 }}</h3> 9 10 {% for i in context2 %} 11 <p>{{ i }}</p> 12 {% endfor %} 13 14 15 {% endblock %}