Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

整合admin美化的后台Jet后报错 #1

Open
x2x4com opened this issue May 7, 2019 · 3 comments
Open

整合admin美化的后台Jet后报错 #1

x2x4com opened this issue May 7, 2019 · 3 comments

Comments

@x2x4com
Copy link

x2x4com commented May 7, 2019

官方的后台太丑了,实际项目里面我们都会引一个美化的admin的插件Jet,但是打开Jet后就报错了
Jet: https://github.com/geex-arts/django-jet

渲染模板的时候Jet模板报错,指向的是wechat_django/admin/base.py的has_wechat_permission这个方法

AttributeError at /site/admin/
'WSGIRequest' object has no attribute 'app'
Error during template rendering
In template /Volumes/Git/github/x2x4/site_base/venv/lib/python3.6/site-packages/jet/templates/admin/base.html, error at line 199

该模板文件报错行

 {% jet_get_menu as app_list %}

实际报错 wechat_django/admin/base.py in has_wechat_permission, line 162

    def has_wechat_permission(self, request, operate="", category="", obj=None):
        app = request.app
        category = category or self.__category__
        return has_wechat_permission(request, app, category, operate, obj)

请问这个app的属性是什么时候塞进去的? 怎么修复呢

@Xavier-Lam
Copy link
Owner

request.app是在此处插入的
https://github.com/Xavier-Lam/wechat-django/blob/master/wechat_django/sites/admin.py#L125
如果不是使用django.contrib.admin.site 而是自建AdminSite,继承时把wechat_django.sites.WeChatAdminSiteMixin mixin进去看看能否解决

@Xavier-Lam
Copy link
Owner

看了一下 应该是由于django-jet取菜单的时候 直接取了子菜单导致的 简单的处理方法就是 在
wechat_django.admin.base.has_wechat_permissionwechat_django.admin.base.has_module_permission方法中首行添加

        if not hasattr(request, "app"):
            return False

跳过对request.app的验证

但是这样跳过会造成微信相关左侧导航混乱

@x2x4com
Copy link
Author

x2x4com commented May 8, 2019

return False后的确引起了各种页面的混乱,而且风格也有蛮大的偏差。

以前用过一个PHP的微信管理工具-微擎, 除了PHP其他都挺好的,所以想找个Python的类似工具,但是找了几个都不太舒服,可能是微擎的完成度放到的很高。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants