Django写业务流程

1.编写html模板文件,会使用Django的标签

a.html:

<tbody>

{% block table_head %}#模板块,可以被子模板替换

    {% autoescape off %}#自动转义关闭,相关文章参考:http://dikar.iteye.com/blog/305977

        {{table_body}}#后台传入的值

    {% endautoescape %}

{% endblock %}

</tbody>

b.html:

     {% extends "a.html" %}#可以继承自父类的模板

     {% block table_head %}

               {{table_body_sub}}#以新值替换父类中的值

         {% endblock %}

 

2.修改ulr的配置,使得能找到对应路径的服务类

urlpatterns = patterns('',

                       url(r'sap_comparison_history', SapComparisonHistoryTableView.as_view(), name='sap_comparison_history')

) #这样配置就使得/sap_comparison_history对应的处理类为SapComparisonHistoryTableView

 

3.创建对应的view处理类

class SapComparisonHistoryTableView(TemplateView):#必须继承自TemplateView类

    template_name = "show_comparison_history_by_cc.html" #指明该view所对应的html页面,默认路径在templates目录下

 

    def get_context_data(self, **kwargs): #默认调用方法,当调用该view时

        # TODO need get cc_id from url

        params = retrieve_param(self.request) #获取request中的数据

        cc_id = params["cc_id"]

        kwargs["table_body"] = self.get_table_str(cc_id) #获取数据并组装成html格式放入map中

        kwargs["cc_id"] = cc_id

        return kwargs #返回map供前端页面使用

 

    def get_table_str(self, cc_id):

        res = ''

        for info in SapComparisonResultSnapshot.objects.filter(costcenter=cc_id).order_by('version_index'):

            res += '<tr>'

            res += '<td align="center">%s</td>' % info.onlybooking

            res += '<td align="center">%s</td>' % info.onlysap

            res += '<td align="center">%s</td>' % info.snapshot_date.strftime("%Y-%m-%d %H:%M:%S")

            res += '<td align="center">%s</td></tr>' % info.version_index

        return res

转载于:https://my.oschina.net/ffse54s/blog/824119

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值