Django xadmin 添加自定义页面
1.在adminx.py文件中添加一下内容:
#设置全局的设置类 class GlobalSettings(object): site_title="频道后台管理" site_footer="其它" # menu_style = 'accordion' """ 自定义页面 """ def get_site_menu(self): return [ { 'menus': ( { 'title': '测试菜单', 'url': '/xadmin/test_view', # 'icon': 'fa fa-cny' }, ) } ] #注册要跳转的视图函数 xadmin.site.register_view(r'test_view/$', TestView, name='test')
2.在views.py文件中添加以下内容:
from xadmin.views import CommAdminView import time,hashlib 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,'test.html',context) def get_url(self, app_name, stream_name): t = time.time() + 172800 keytime = str(int(t)) hashstring = "/" + app_name + "/" + stream_name + "-" + keytime + "-0-0-" + app_name + "alipush" m = hashlib.md5() m.update(hashstring.encode("utf8")) mm = m.hexdigest() print(mm) push = "rtmp://" + app_name + "alipush.v.myalicdn.com/" + app_name + "/" + stream_name + "?auth_key=" + keytime + "-0-0-" + mm return push def post(self, request): print('mmmmmmmmmmmmm') app_name = request.POST.get('app') stream_name = request.POST.get('name') context = super().get_context() title = "测试" context["breadcrumbs"].append({'url': '/cwyadmin/', 'title': title}) context["title"] = title context['app_name'] = app_name context['streaa_name'] = stream_name context['push'] = self.get_url(app_name,stream_name) return render(request,'test.html', context) # 最后指定自定义的template模板,并返回context
3.在url.py中添加路由:
url(r'xadmin/test_view/',views.TestView.as_view()),