HTML类

class Html:
    def __init__(self,name):
        self.name = name

    @staticmethod
    def full_name():
        print('全称:Hype Text Makeup Language')
        print('中文名称:超文本标记语言')

    @staticmethod
    def history():
        print('历史:')
        dic = {}
        dic.setdefault('1.0版本',1993.06)
        dic.setdefault('2.0版本',1995.11)
        dic.setdefault('3.2版本',1997.01)
        dic.setdefault('4.01版本',1999.12)
        dic.setdefault('4.01版本',2000.05)
        dic.setdefault('5.0版本',2014.10)
        for k, v in dic.items():
            print('版本:', k, '\t时间: ',v)

    @staticmethod
    def type():
        print('< !DOCTYPE html >')  # 声明是哪个版本的

    def html_first(self,content=None):
        res='<html>\n%s%s\n</html>' % (self.head(),self.body(content))
        print(res)
        return res

    def structure(self):
        '''html结构'''
        self.type()
        self.html_first()

    def head(self):
        res = '<head>\n<title>%s</title>\n</head>\n' % self.name
        return res

    @staticmethod
    def body(content):
        res = '<body>\n%s\n</body>' % content
        return res

    @staticmethod
    def black(n=1):
        '''空白符号'''
        res = '&nbsp' * n
        return res

    @staticmethod
    def show_label():
        print("""
                        1:h1-h6,标题
                        2:p,段落
                        3:strong/em,强调
                        4:hr,文章与文章间的分割
                        5:br,换行
                        6:ul/ol,列表
                        7:div/span,排版布局
                        8:li,粒
                        9:table,表格
                        10:a,超链接
                        11:img,图片
                        12:from,列表,服务器交互
                        13:input,输入
                        14:textarea,多行输入
                        15:select,下拉列表\n
                    """)
HTML类
class Label:
    '''单闭合标签'''
    @staticmethod
    def br():
        '''换行,注意空白折叠现象'''
        return '<br>'

    @staticmethod
    def hr():
        '''文章和文章之间进行添加横线'''
        return '<hr>'

    @staticmethod
    def meta(mode='UTF-8'):
        '''字符编码是gbk还是utf8'''
        return '<meta charset=%s>' % mode

    @staticmethod
    def img():
        '''图片标签'''
        return '<img >'

    @staticmethod
    def input(type,content,check='check',name='',placeholder='',value=''):
        '''
        和from表单结合使用
        :param type:明文:text,密文:password,圆点:radio,复选框:checkbox,重置:reset(针对from)
        :param content: 显示内容
        :param check: 默认选中(有选择框)
        :param name: 互斥
        :param placeholder:提示
        :param value:按钮上显示的内容,发送给服务端
        :return:
        '''
        return "%s<input type='%s' placeholder='%s' name='%s' check='%s' value='%s'>" \
               % (content,type,placeholder,name,check,value)
单闭合标签 HTML类
class Label1:
    '''多闭合标签'''
    @staticmethod
    def p(content=None):
        '''段落标签'''
        return '<p>%s</p>' % content

    @staticmethod
    def strong(content=None):
        '''文本内容加粗,重强调'''
        return '<strong>%s</strong>' % content

    @staticmethod
    def em(content=None):
        '''文本内容斜体,轻强调'''
        return '<em>%s</em>' % content

    @staticmethod
    def li(args=None):
        '''
        粒标签
        :param args:元组
        :return:
        '''
        res = ''
        for i in args:
            single = '<li>%s</li>\n' % i
            res += single
        return res

    @staticmethod
    def ul(li=None):
        '''无序列表(unorder line)'''
        return '<ul>\n%s\n</li>' % li

    @staticmethod
    def ol(li=None):
        '''有序列表(order line)'''
        return '<ol>\n%s\n</ol>' % li

    @staticmethod
    def dl(title=None,describe=None):
        '''
        定义列表
        :param title:元组
        :param describe: 元组
        :return:
        '''
        res1 = ''
        for i in title:
            single1 = '<dt>%s</dt>\n' % i
            res1 += single1
        res2 = ''
        for i in describe:
            single2 = '<dd>%s</dd>\n' % i
            res2 += single2
        res= '<dl>\n%s%s</dl>' % (res1,res2)
        return res

    @staticmethod
    def table(head=None,describe=None,caption=None,border=0):
        '''

        :param head:
        :param describe:元组,一个元素代表一行,一个元素有多少项代表有多少列,如((xx,xx),(xx,xx))
        :param border: 宽度
        :return:
        '''
        res0 = '<caption>%s</caption>\n' % caption
        res1 = ''
        for i in head:
            all_head = ''
            single1 = '<th>%s</th>\n' % i
            all_head += single1
            res1 += all_head
        res1 = '<tr>\n' + res1 + '</tr>\n'
        res2 = ''
        for t in describe:
            all_head = ''
            for i in t:
                single2 = '<td>%s</td>\n' % i
                all_head += single2
            res3 = '<tr>\n' + all_head + '</tr>\n'
            res2 += res3

        res = "<table border='%d'>\n%s%s%s</table>" % (border,caption,res1, res2)
        return res

    @staticmethod
    def a(web=None,name=None,target='self'):
        '''段落标签'''
        return "<a href='%s' target='%s'>%s</a>" % (web,target,name)

    @staticmethod
    def textarea(rows=None,cols=None):
        '''文本域标签'''
        if rows and cols:
            return '<textarea rows="%s" cols="%s"></textarea>' % (rows,cols)
        else:
            return '<textarea></textarea>'

    @staticmethod
    def laber(id=None,text=None):
        '''标记标签,鼠标点击文本后跳转到关联的from内容'''
        return '<laber for="%s">%s</laber>' % (id,text)

    @staticmethod
    def div(content=None):
        '''区隔标签'''
        return '<div>\n%s\n</div>' % content

    @staticmethod
    def select(content=None,multiple='multiple'):
        '''选择标签'''
        return '<select multiple="%s">%s</select>' % (multiple,content)

    @staticmethod
    def option(content=None,value='',selected=''):
        '''选项标签,会根据内容数目自动出现滚筒'''
        if value:
            return '<option value="%s" selected="%s">%s</option>' % (value,content,selected)
        else:
            return '<option value="%s" selected="%s">%s</option>' % (content,content,selected)

    @staticmethod
    def from_html(content=None,action='#',method='get'):
        '''
        from表单标签
        :param content:
        :param action: 服务器地址
        :param method:
        :return:
        '''
        return '<from action="%s" method="%s">\n%s\n</from>' % (action,method,content)
多闭合标签

 

上一篇:classmethod类方法和staticmethod 方法


下一篇:Python中classmethod和staticmethod的区别