推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
killpanda
V2EX  ›  Python

Django下富文本显示的问题

  •  
  •   killpanda ·
    killpanda · Nov 22, 2011 · 5596 views
    This topic created in 5422 days ago, the information mentioned may be changed or developed.
    我刚学Web开发,自己正在练习一点一点写一个博客程序。我为我的程序添加了TinyMCE,可是显示文章内容出了问题。

    在页面里,显示的内容却是这样的:
    <p><span style="font-family: 'arial black', 'avant garde'; font-size: medium;">It works!</span></p>

    查看页面的代码为:

    <h1><p>Hello World</p></h1>
    &lt;p&gt;&lt;span style=&quot;font-family: &#39;arial black&#39;, &#39;avant garde&#39;; font-size: medium;&quot;&gt;It works!&lt;/span&gt;&lt;/p&gt;

    我的html模板是这样的:
    <h1><p>{{ blog.head }}</p></h1>
    {{ blog.body }}

    请问如何处理这个问题?
    谢谢了!
    3 replies  •  1970-01-01 08:00:00 +08:00
    SErHo
        1
    SErHo  
       Nov 22, 2011
    这个是自动转义了,可以用safe过滤器为单独的变量关闭自动转意,如{{ blog.body|safe }} ,详细参考:http://djangobook.py3k.cn/2.0/chapter09/#cn77
    killpanda
        2
    killpanda  
    OP
       Nov 22, 2011
    @SErHo 感谢!!确实是这个问题!
    我才看了前4章,所以遇到了这些弱智的问题,还不会解决,呵呵。

    谢谢了
    loading
        3
    loading  
       Nov 24, 2011
    学习了!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1343 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:51 · PVG 00:51 · LAX 09:51 · JFK 12:51
    ♥ Do have faith in what you're doing.