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()),


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM