librelist archives

« back to archive

Working with modules. Finding the base template

Working with modules. Finding the base template

From:
Mathias Nielsen
Date:
2010-12-19 @ 01:52
Hi, trying out Flask and I'm having a bit of a problem.
I have a structure like this:
/project2
    __init__.py
    /templates
        base.html
    /apps
        __init__.py
        /frontend
            __init__.py
            views.py
            /templates
                front.html

I have followed the example in the docs and have this in my
project/__init__.py

from flask import Flask
from apps.frontend.views import frontend

app = Flask(__name__)

app.config.from_object('settings')
app.register_module(frontend, url_prefix='/')

if __name__ == '__main__':
app.run()


In frontend/views.py I can use both base.html and views/front.html with
success, but if I want front.html to extend base.html I get a
TemplateNotFound error.

When inspecting I can see that it is looking for this base.html template in
the folder that contains my project2 folder.

/Projects/project2/templates <-- Where base.html really is
/Projects/templates <-- where Flask/Jinja looks for it

Why on earth does it look there?

Hopefulle its just something stupid I have missed, but I just cant see it.
Maybe someone here can help.

-- 
Best regards

Mathias Nielsen

Re: [flask] Working with modules. Finding the base template

From:
Dag Odenhall
Date:
2010-12-19 @ 12:27
On Sun, 2010-12-19 at 02:52 +0100, Mathias Nielsen wrote:

> Why on earth does it look there?


http://flask.pocoo.org/docs/patterns/packages/#simple-packages

        
        But how do you run your application now? The naive python
        yourapplication/__init__.py will not work. Let’s just say that
        Python does not want modules in packages to be the startup
        file. 

Re: [flask] Working with modules. Finding the base template

From:
Simon Sapin
Date:
2010-12-19 @ 12:34
Le 19/12/2010 21:27, Dag Odenhall a écrit :
>
>     But how do you run your application now? The naive python
>     yourapplication/__init__.py will not work. Let's just say that
>     Python does not want modules in packages to be the startup file. 
>

Hi,

Do you mean having an executable script that you can run from a 
terminal? For that I have the following entry in my setup.py
     entry_points={'console_scripts': ['manage=myapp.manage:manager.run']}
(Here using Flask-Script.)
and let pip+virtualenv or buildout do their job. (eg. pip install -e .)

See http://flask.pocoo.org/docs/patterns/distribute/

Regards,
-- 
Simon