V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2014-07-15 19:55:50 +08:00 · 7237 次点击
    这是一个创建于 3576 天前的主题,其中的信息可能已经有所发展或是发生改变。
    初学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 条回复    2014-07-17 22:21:03 +08:00
    forreal
        1
    forreal  
    OP
       2014-07-15 23:35:04 +08:00
    解决了,直接{% extends "base.html"%}就可以,哪怕不在同一个文件夹里。估计是加载到jinja2的环境里了。
    neutrous
        2
    neutrous  
       2014-07-16 16:31:06 +08:00   ❤️ 1
    默认的Flask实例会使用templates文件夹作为模板的目录,此目录会作为jinja2渲染的根目录
    zjnjxufe
        3
    zjnjxufe  
       2014-07-16 16:35:50 +08:00   ❤️ 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  
       2014-07-16 16:36:23 +08:00   ❤️ 1
    格式乱掉了 o(╯□╰)o
    forreal
        5
    forreal  
    OP
       2014-07-17 20:04:43 +08:00
    @zjnjxufe
    虽然乱掉了,但是大致了解了。我主要是想模仿django的app形式。
    forreal
        6
    forreal  
    OP
       2014-07-17 20:06:04 +08:00
    @neutrous
    学习了,多谢
    forreal
        7
    forreal  
    OP
       2014-07-17 22:21:03 +08:00
    @zjnjxufe
    其实这么写和django的app的组织形式也差不多,而且比较简洁
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3115 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:34 · PVG 20:34 · LAX 05:34 · JFK 08:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.