-2

autoescape django テンプレートタグの使用に問題があります ここに私のコードがあります

msg="<p><b>Location. </b> <br />Marriott Dallas Addison Quorum Galleria is located in Dallas's Addison - Galleria neighborhood, close to Galleria Dallas, Cavanaugh Flight Museum, and Northwood Club. Additional area points of interest include University of Texas at Dallas. </p><p><b>Hotel Features. </b><br />Dining options at Marriott Dallas Addison Quorum Galleria include a restaurant and a coffee shop/café. A bar/lounge is open for drinks. Room service is available. The hotel serves buffet breakfasts (surcharges apply). Recreational amenities include an outdoor pool, an indoor pool, and a spa tub. This 3.5-star property has a business center and offers small meeting rooms, limo/town car service, and audio-visual equipment. Wireless Internet access (surcharge) is available in public areas. The property offers a roundtrip airport shuttle (surcharge).  Guest parking is available for a surcharge. Additional property amenities include a concierge desk, gift shops/newsstands, and ATM/banking services. </p><p><b>Guestrooms. </b> <br /> 547 air-conditioned guestrooms at Marriott Dallas Addison Quorum Galleria feature coffee/tea makers and complimentary newspapers. Wired high-speed and wireless Internet access is available for a surcharge. In addition to desks, guestrooms offer multi-line phones with voice mail. Televisions have premium cable channels and pay movies. Rooms also include hair dryers and irons/ironing boards. A turndown service is available nightly, housekeeping is offered daily, and guests may request wake-up calls. </p> <br /><br /> <p><strong>Notifications and Fees:</strong><br /></p><p></p><p></p><p></p><p>The following fees and deposits are charged by the property at time of service, check-in, or check-out.  <ul><li>Self parking fee: USD 12 per day</li><li>Valet parking fee: USD 17 per day</li><li>Fee for wireless Internet in public areas: USD 3.95 per day (rates may vary)</li> <li>Fee for in-room high-speed Internet (wired): USD 12.95 per day (rates may vary)</li><li>Fee for in-room wireless Internet: USD 12.95 per day (rates may vary)</li><li>Buffet breakfast fee: USD 17 per person (approximate amount)</li> </ul></p><p>The above list may not be comprehensive. Fees and deposits may not include tax and are subject to change. </p> <br /><br /> <p><strong>Notifications and Fees:</strong><br /></p><p></p><p></p><p></p><p>The following fees and deposits are charged by the property at time of service, check-in, or check-out.  <ul><li>Self parking fee: USD 12 per day</li><li>Valet parking fee: USD 17 per day</li><li>Fee for wireless Internet in public areas: USD 3.95 per day (rates may vary)</li> <li>Fee for in-room high-speed Internet (wired): USD 12.95 per day (rates may vary)</li><li>Fee for in-room wireless Internet: USD 12.95 per day (rates may vary)</li><li>Buffet breakfast fee: USD 17 per person (approximate amount)</li> </ul></p><p>The above list may not be comprehensive. Fees and deposits may not include tax and are subject to change. </p>"

{% autoescape off %}{{msg}}{% endautoescape %} 

まだhtmlタグが表示されていますか?

4

4 に答える 4

1

これを試して:

{% filter escape %} msg {% endfilter %}

状況によっては、force_escape フィルターを使用する必要がある場合もあります。

于 2012-04-09T13:35:45.660 に答える
0

私はあなたを完全にフォローしているわけではありませんが、試しましたか

{{ msg|safe }}
于 2012-04-11T03:31:53.150 に答える
0

エスケープされたテキストがモデルのフィールドから来ている場合 (または別の方法でバックエンドから来ている場合)、(人々がすでに言ったことに加えて)mark_safeテンプレートで何かをするのではなく、Python コード内で使用できます。ここを参照してください: https://docs.djangoproject.com/en/dev/ref/utils/#django.utils.safestring.mark_safe

モデルのフィールドに、自動エスケープされる文字が一貫して入力されているとします。安全とマークされた値を返すメソッドをモデルに追加したい場合があります。例えば:

from django.utils.safestring import mark_safe

class Something(models.Model):
    html_text = models.CharField(max_length=30)
    #...

    def get_html(self):
        return mark_safe(self.html_text)

次に、テンプレートで使用するだけです{{ my_something.get_html }}

于 2013-04-16T04:13:28.683 に答える