2015-12-09 41 views
1

Django模板是我的工作空間/項目名稱/模板/應用程序的名字裏面的index.html文件顯示html標籤,因爲它是低於

<!DOCTYPE html> 
<html> 

    <head> 
     <title>my news</title> 
    </head> 

    <body> 
     <h1>look below for news</h1> 
     {%if categories%} 
      <ul> 
       {%for category in categories%} 
        <li>{{category.name}}</li> 

       {%endfor%} 
      </ul> 

     {%endif%} 

     {%if headings%} 

      <p> 
       {%for heading in headings%} 

        <a href="#">{{heading.title}}</a> 
        <br> 
        {{heading.content}} 

       {%endfor%} 
      </p> 

     {%endif%} 
    </body> 

</html> 

問題<ul><li>標籤工作,顯示該表,因爲它應該這樣做。<a>標籤也顯示一個超鏈接,但<p>標籤和<br>標籤沒有被呈現,並顯示爲一個文本,不能認爲可能是什麼問題。我對django相當新。 index.html

回答

2

雖然,另一個答案准確地解決了你的問題,但是這種方法每次都不安全。

如果您知道只有值得信賴的人才會撰寫該文章/帖子,那麼您可以簡單地轉向Django的autoescaping off(如其他答案中指出的那樣)。

但是,如果您想要顯示來自不可信來源的HTML,則很容易受到XSS攻擊。在這種情況下,您應該使用像django-bleach這樣的應用程序。它會轉義特定的HTML標籤,如<script>和任何其他您想要轉義的標籤。

相關問題