推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
kkjj
V2EX  ›  Python

django 加入装饰器之后出现 view must be a callable or a list/tuple in the case of include().')

  •  
  •   kkjj · Dec 23, 2017 · 4066 views
    This topic created in 3199 days ago, the information mentioned may be changed or developed.

    django 加入装饰器之后出现 view must be a callable or a list/tuple in the case of include().')的错误,把装饰器注释掉又恢复正常,有没人知道这是怎么回事

    8 replies  •  2017-12-24 16:21:13 +08:00
    Zioyi
        1
    Zioyi  
       Dec 23, 2017
    看你代码,加了什么装饰器
    kkjj
        2
    kkjj  
    OP
       Dec 23, 2017
    @Zioyi
    #@user_decorator.login
    def user_center_order(request):
    context={
    'title':"订单中心"
    }
    return render(request,'df_user/user_center_order.html',context)
    增加了验证用户登录的装饰器
    装饰器如下:
    def login(func):
    def login_fun(request,*args,**kwargs):
    if request.session.has_key('user_id'):
    return func(request,*args,**kwargs)
    else:
    red=HttpResponseRedirect('user/login/')
    red.set_cookie('url',request.get_full_path())
    return red
    return login_fun
    wangyongbo
        3
    wangyongbo  
       Dec 23, 2017
    从代码里面看不出来错误, 实际测试了一下, 也没有问题呀。
    Ehco1996
        4
    Ehco1996  
       Dec 24, 2017 via iPhone
    Django 有自带的等级权限装饰器

    login_required
    Zioyi
        5
    Zioyi  
       Dec 24, 2017
    @kkjj 你的路由怎么写的
    kkjj
        6
    kkjj  
    OP
       Dec 24, 2017
    @Zioyi 谷歌了,说路由不能用字符串了,改了还是出现一样的问题
    kkjj
        7
    kkjj  
    OP
       Dec 24, 2017
    @Ehco1996 学习了
    kkjj
        8
    kkjj  
    OP
       Dec 24, 2017
    @wangyongbo 所以觉得奇怪,把装饰器注释掉就没有报错
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2619 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 12:18 · PVG 20:18 · LAX 05:18 · JFK 08:18
    ♥ Do have faith in what you're doing.