码迷,mamicode.com
首页 > 其他好文 > 详细

遍历修改django bootstrap form 为 django bootstrap3

时间:2017-04-08 01:01:41      阅读:296      评论:0      收藏:0      [点我收藏+]

标签:horizon   load   write   div   files   false   修改   bin   join   

#!/usr/bin/env python
# encoding: utf-8

import re
import os

fname = ‘‘

bt_pattern = re.compile(r‘{% load bootstrap .*‘)
field_pattern = re.compile(r‘(\s*){{\s*(form\.\w+)\|\s*bootstrap_horizontal\s*}} *‘)


def bs2bs3(fn):
    with open(fn) as f:
        content = f.read()

    content = bt_pattern.sub(r‘{% load bootstrap3 %}‘, content)
    content = field_pattern.sub(r‘\1{% bootstrap_field \2 layout="horizontal" %}‘, content)

    with open(fn, ‘w‘) as f:
        f.write(content)


def walk_dir(dirname):
    for root, dirs, files in os.walk(dirname, topdown=False):
        for name in files:
            fname = os.path.join(root, name)
            bs2bs3(fname)

  

遍历修改django bootstrap form 为 django bootstrap3

标签:horizon   load   write   div   files   false   修改   bin   join   

原文地址:http://www.cnblogs.com/cmsd/p/6680401.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!