2012-04-09 28 views
-2

私はここautoescape Djangoテンプレートタグを使用して問題を持っているが、私のコードエスケープhtmlタグ

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タグを示しているのですか?

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

か、

+0

を使用しています。その 'msg ='行はどういう意味ですか?私はそれがテンプレート変数の想定される文字列値だと思いますか?そして、「htmlタグを表示する」とはどういう意味ですか?それはどのように現れますか?どのように表示されますか? –

答えて

1

これを試してみてくださいいくつかの変数にあなたのhtmlコンテンツを入れたいし、それをテンプレートにエスケープして、それを通常のhtmlとして使いたいと思ってはいけません。その場合には、

msg = "<p>Location</p>" 
{% autoescape off %}{{msg}}{% endautoescape %} 
0

私は完全にあなたに従わない状況に応じて、force_escapeフィルタを使用する必要があるかもしれませんが、あなたは

{{ msg|safe }} 
0

はそうしようとしている:

0

あなたのエスケープ文字は、モデル内のフィールドから(または別の方法でバックエンドから来る)されている場合は、(人々がすでに言ったことに加えて)あなたの内mark_safeを使用することができますPythonコードではなく、テンプレートで何かをしています。モデルのフィールドに一貫してオートエスケープされる文字が設定されているとします。安全とマークされた値を返すメソッドをモデルに追加することができます。たとえば:

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 }}