V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
forreal
V2EX  ›  Python

请教一个 flask 模板{% extends%}的问题

  •  
  •   forreal · Jul 15, 2014 · 8191 views
    This topic created in 4314 days ago, the information mentioned may be changed or developed.
    初学flask,想利用蓝图把网站分成一个个app的形式(类似django)
    想让blueprint1中的templates中的模板(show.html)extends application的templates中的base.html
    该如何做?
    目录是
    /application
    ----/__init__.py
    ----/views.py
    ----/static
    --------/main.css
    ----/templates
    --------/base.html
    /blueprint1
    ----/__init__.py
    ----/views.py
    ----/templates
    --------/show.html
    7 replies    2014-07-17 22:21:03 +08:00
    forreal
        1
    forreal  
    OP
       Jul 15, 2014
    解决了,直接{% extends "base.html"%}就可以,哪怕不在同一个文件夹里。估计是加载到jinja2的环境里了。
    neutrous
        2
    neutrous  
       Jul 16, 2014   ❤️ 1
    默认的Flask实例会使用templates文件夹作为模板的目录,此目录会作为jinja2渲染的根目录
    zjnjxufe
        3
    zjnjxufe  
       Jul 16, 2014   ❤️ 1
    /application
    --apps
    --blueprint1.py
    --blueprint2.py
    --static
    --templates
    --base.html
    --b1
    --base_b1.html --> {% extends base.html %}
    --xx.html
    --b2
    --base_b2.htlm --> {% extends base.html %}
    --xx.html

    这种格式试过没。。
    zjnjxufe
        4
    zjnjxufe  
       Jul 16, 2014   ❤️ 1
    格式乱掉了 o(╯□╰)o
    forreal
        5
    forreal  
    OP
       Jul 17, 2014
    @zjnjxufe
    虽然乱掉了,但是大致了解了。我主要是想模仿django的app形式。
    forreal
        6
    forreal  
    OP
       Jul 17, 2014
    @neutrous
    学习了,多谢
    forreal
        7
    forreal  
    OP
       Jul 17, 2014
    @zjnjxufe
    其实这么写和django的app的组织形式也差不多,而且比较简洁
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4264 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 54ms · UTC 00:56 · PVG 08:56 · LAX 17:56 · JFK 20:56
    ♥ Do have faith in what you're doing.