代码之家  ›  专栏  ›  技术社区  ›  Linh Nguyễn Ngọc

如何将{{}}从数据库发送到flask jinja2

  •  0
  • Linh Nguyễn Ngọc  · 技术社区  · 4 年前

    我有一个案例来呈现一个从SQL数据库到jinja2的模板。

    在table shop中,我有一个类似于列的字符串值shop.sms\u车身桌子店的老板!

    {{ location.name }} kính chào quý khách! 
    Đã {{ order.days }} ngày kể từ đơn hàng {{ order.order_name }}, chúng tôi rất mong ý kiến của quý khách để ngày càng phục vụ khách hàng tốt hơn. 
    Mong quý khách liên hệ chúng tôi qua số phone {{ location.phone }}, hoặc ghé thăm website {{ location.address1 }}! 
    Chúng tôi chân thành cám ơn
    

    <a class="text-left"
                           href="sms:{{ order.canonicalForm }}&body={{ shop.sms_body|safe }}"><img
                                src="/static/img/sms_icon.png" width="30px"></a>
    

    当我点击“短信”这是我想要的: {{ location.name }}.. 等必须渲染手机的位置,但它仍然像图像

    SMS message still remain {{}} tag

    有人能解决这个案子吗?

    提前谢谢

    1 回复  |  直到 4 年前
        1
  •  1
  •   Linh Nguyễn Ngọc    4 年前

    谢谢! 我找到解决办法 烧瓶

    sms_body = shop.sms_body
        print(sms_body)
        sms_body = Template(sms_body)
        list_sms_body = [sms_body.render(shop=shop, location=location, order=order) for order in orders]
        if orders == []:
            return redirect(url_for("remind.update_remind_customer", date=date))
        else:
            return render_template('/remind_customer.html', orders=orders, shop=shop, location=location, date=date,
                                   next_date=next_date, pre_date=pre_date, list_sms_body=list_sms_body)
    

    之后在html中

    {% if shop.use_remind_customers == True %}
                {% for index in range(orders|length) %}
                    {% set order = orders[index] %}
                    {% set sms_body = list_sms_body[index] %}
    <a class="text-left"
                               href="sms:{{ order.canonicalForm }}&body={{ sms_body|safe }}"><img
                                    src="/static/img/sms_icon.png" width="30px"></a>
    {% endfor %}
    {% endif %}
    
        2
  •  0
  •   Adithya    4 年前

    你看过吗 escaping raw 为此阻止