推荐学习书目
› 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
P9
V2EX  ›  Python

DJango 表单字段添加 Class 最干净的做法

  •  
  •   P9 · Feb 20, 2016 · 2578 views
    This topic created in 3869 days ago, the information mentioned may be changed or developed.

    分享一个 包 https://github.com/kmike/django-widget-tweaks

    避免 Python Code 层面修改代码
    从此告别
    """
    def init(self, *args, **kwargs):
    super(SampleClass, self).init(*args, **kwargs)
    self.fields['name'].widget.attrs['class'] = 'my_class'

    """"

    在模版层面即可添加!
    多么 DRY 的做法!

    1 replies  •  2016-02-21 04:13:21 +08:00
    pynix
        1
    pynix  
       Feb 21, 2016
    貌似还不错。。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   956 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 19:00 · PVG 03:00 · LAX 12:00 · JFK 15:00
    ♥ Do have faith in what you're doing.