推荐学习书目
› 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
cc7756789
V2EX  ›  Python

flask 使用 markdown 无效

  •  
  •   cc7756789 · Jun 10, 2015 · 4009 views
    This topic created in 4146 days ago, the information mentioned may be changed or developed.

    我是按照这个教程上的 Using the markdown language

    我的代码 :

    from flask import Markup
    import markdown
    from flask import Flask
    from flask import render_template
    
    @app.route('/mark')
    def mark():
        con = """
            Chapter
            =======
    
            Section
            -------
    
            * Item 1
            * Item 2
            """
        contents= Markup(markdown.markdown(con))
        return render_template('mark.html', content=contents)
    

    html代码:

    <html>
      <head>
        <title>Markdown Snippet</title>
      </head>
      <body>
      {% if content %}
        {{ content }}
      {% endif %}
      </body>
    </html>
    

    访问结果是这样, 原封不动输出:

    Chapter
    =======
    
    Section
    -------
    
    * Item 1
    * Item 2
    
    6 replies  •  2015-06-11 15:48:22 +08:00
    imlonghao
        1
    imlonghao  
       Jun 10, 2015
    你的con前面被你加了空格?
    imlonghao
        2
    imlonghao  
       Jun 10, 2015
    con = """
    Chapter
    =======

    Section
    -------

    * Item 1
    * Item 2
    """
    cc7756789
        3
    cc7756789  
    OP
       Jun 10, 2015
    @imlonghao 谢谢,果然是这个坑
    imlonghao
        4
    imlonghao  
       Jun 10, 2015
    imlonghao
        5
    imlonghao  
       Jun 10, 2015
    elvis_w
        6
    elvis_w  
       Jun 11, 2015
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2997 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 01:45 · PVG 09:45 · LAX 18:45 · JFK 21:45
    ♥ Do have faith in what you're doing.