V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
chionyuan
V2EX  ›  Python

问大佬们一个问题,关于反射机制

  •  
  •   chionyuan · 2019-07-10 16:52:38 +08:00 · 2124 次点击
    这是一个创建于 1724 天前的主题,其中的信息可能已经有所发展或是发生改变。

    想知道类似于 DRF 框架里面的。   1.局部使用:authentication_classes=[AuthLogin] 像局部使用,在当前文件下应用这些类,怎么实现呢, 附上大图,第一次发帖,好紧张2bb7cb43e97c2edeca8a3a86b653f22.png

    5 条回复    2019-07-11 11:30:22 +08:00
    ebingtel
        1
    ebingtel  
       2019-07-10 19:40:02 +08:00
    类似 importlib.import_module('os.path')
    chionyuan
        2
    chionyuan  
    OP
       2019-07-10 20:28:50 +08:00
    不是这样的,我的意思是有没有那种列表里放了几个类。就运行这样,就像 drf 框架里面的局部配置一样的
    txy3000
        3
    txy3000  
       2019-07-10 21:13:17 +08:00
    你就参考 Django add_routes 的思路呗
    大致就是类似
    mod = __import__(module_name, globals(), locals())
    for attr in dir(mod):
    fn = getattr(mod, attr)
    zhoudaiyu
        4
    zhoudaiyu  
       2019-07-10 21:18:28 +08:00 via iPhone
    这是啥主题?
    chionyuan
        5
    chionyuan  
    OP
       2019-07-11 11:30:22 +08:00
    @txy3000 我试试,大概是这样,谢谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2482 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 15:45 · PVG 23:45 · LAX 08:45 · JFK 11:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.