librelist archives

« back to archive

Template directory

Template directory

From:
Jonas Galvez
Date:
2011-01-14 @ 18:23
Is there a config variable to change it? Couldn't find any.

-- Jonas

Re: Template directory

From:
Jonas Galvez
Date:
2011-01-14 @ 18:24
I guess this is the only way to do it?

from jinja2 import FileSystemLoader
template_path = 'my-templates'
app.jinja_loader = FileSystemLoader(os.path.join(ROOT_PATH, template_path))

-- Jonas

On Fri, Jan 14, 2011 at 4:23 PM, Jonas Galvez <jonasgalvez@gmail.com> wrote:

> Is there a config variable to change it? Couldn't find any.
>
> -- Jonas
>

Re: [flask] Re: Template directory

From:
Armin Ronacher
Date:
2011-01-15 @ 00:46
Hi,

On 2011-01-14 7:24 PM, Jonas Galvez wrote:
> I guess this is the only way to do it?
>
> from jinja2 import FileSystemLoader
> template_path = 'my-templates'
> app.jinja_loader = FileSystemLoader(os.path.join(ROOT_PATH, template_path))
That's one way.  Generally the Jinja2 environment is created by the 
Flask create_jinja_environment() method.  If you want to hook into the 
creation process, subclass the Flask class and override that method.

Why is there no configuration for the template folder?  Because each 
module can provide its own template folder and it quickly would become 
confusing if the application would override the template folder. 
However I might have missed a use case, so I am not 100% behind the 
current "hardcoded" path.


Regards,
Armin

Re: [flask] Re: Template directory

From:
Jonas Galvez
Date:
2011-01-15 @ 12:14
On Fri, Jan 14, 2011 at 10:46 PM, Armin Ronacher wrote:
> That's one way.  Generally the Jinja2 environment is created by the
> Flask create_jinja_environment() method.  If you want to hook into the
> creation process, subclass the Flask class and override that method.

Thanks for the clarification.

> Why is there no configuration for the template folder?  Because each
> module can provide its own template folder and it quickly would become
> confusing if the application would override the template folder.
> However I might have missed a use case, so I am not 100% behind the
> current "hardcoded" path.

The use case is being able to quickly put together a server to serve
some test pages or files in a Fabric task.

Here's the actual snippet: http://paste.pocoo.org/show/320971/

I also created a static-file handler because I couldn't cleanly change
the source for static files either.

-- Jonas