librelist archives

« back to archive

Render_template syntax

Render_template syntax

From:
Date:
2010-08-10 @ 01:59
Is there a reason behind the syntax when modules are concerned?

render_template('admin/list_items.html')

This is a definitive stumbling block If one just jumps into Flask coding, 
because it is misleading, it looks like path on the filesystem. Would a 
keyword argument have not been better like

render_template(template_root_dir = 'admin', 'list_items.html')

CherryPy has something of the sort for its static files. In a web 
application that consists of several other smaller applications/modules 
one can set the the root directories of the static files separately for 
each application, this might help the slightly complicated structure that 
is needed in Flask for larger applications at the moment.

Just my thoughts, I really like Flask and I might convert all my apps to 
use it, my coding experience was just a little dampend when I did some 
testing today trying to code a truly pluggable app that can be re-used 
without much bolierplate code or configuration.
___________________________________________________________
GRATIS für alle WEB.DE Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de

Re: [flask] Render_template syntax

From:
Peter Hansen
Date:
2010-08-11 @ 00:17
On 2010-08-09 9:59 PM, nhytro-python@web.de wrote:
> Is there a reason behind the syntax when modules are concerned?
>
> render_template('admin/list_items.html')
>
> This is a definitive stumbling block If one just jumps into Flask
> coding, because it is misleading, it looks like path on the
> filesystem. Would a keyword argument have not been better like

If I understand you correctly, I would say that it *also* looks like a 
URL, where with routing involving nobody should be assuming that 
"list_items.html" is merely a file inside a container named "admin".

-- 
Peter Hansen

Re: [flask] Render_template syntax

From:
Armin Ronacher
Date:
2010-08-10 @ 06:48
Hi,

On 8/10/10 3:59 AM, nhytro-python@web.de wrote:
> Is there a reason behind the syntax when modules are concerned?
>
> render_template('admin/list_items.html')
I'm open to suggestions on alternative formats for the filename string. 
  It has to be a single string because otherwise you are unable to 
reference other templates from within Jinja2.  Two parameters are not a 
possible solution.


Regards,
Armin

Re: [flask] Render_template syntax

From:
Dag Odenhall
Date:
2010-08-10 @ 13:15
> Hi,
> 
> On 8/10/10 3:59 AM, nhytro-python@web.de wrote:
> > Is there a reason behind the syntax when modules are concerned?
> >
> > render_template('admin/list_items.html')
> I'm open to suggestions on alternative formats for the filename string. 
>   It has to be a single string because otherwise you are unable to 
> reference other templates from within Jinja2.  Two parameters are not a 
> possible solution.
> 
> 
> Regards,
> Armin

I like /, makes it obvious how to override module templates and makes it
easy to support this in Flask-Genshi because Genshi has a
loader.prefixed thing for doing this exactly.

Maybe the docs just needs to be more clear on the subject?

Re: [flask] Render_template syntax

From:
kevin beckford
Date:
2010-08-10 @ 16:41
> Maybe the docs just needs to be more clear on the subject?
>


That's the solution to this issue.  Why change it for all?  What does it gain?

Re: [flask] Render_template syntax

From:
Thadeus Burgess
Date:
2010-08-10 @ 19:12
I also do not mind the / syntax. As it *sorta* makes sense. Why break
backwards compatibility for a syntax issue that could be one way half
a dozen or the other.

--
Thadeus





On Tue, Aug 10, 2010 at 11:41 AM, kevin beckford <chiggsy@lazyweb.ca> wrote:
>> Maybe the docs just needs to be more clear on the subject?
>>
>
>
> That's the solution to this issue.  Why change it for all?  What does it gain?
>

Re: [flask] Render_template syntax

From:
Armin Ronacher
Date:
2010-08-10 @ 20:18
Hi,

On 8/10/10 9:12 PM, Thadeus Burgess wrote:
> I also do not mind the / syntax. As it *sorta* makes sense. Why break
> backwards compatibility for a syntax issue that could be one way half
> a dozen or the other.
Additionally it has the advantage that you can use the posixpath 
functions on such a string.


Regards,
Armin

Re: [flask] Render_template syntax

From:
Date:
2010-08-11 @ 11:34
The only disadvantage that I have seen in the threads is the issue about 
backward-compatibility, this, in my opinion loses some og its weight 
considering the fact that some users might want to use there existing 
jinja templates, like I mentioned a few posts back, I have used the same 
templates without modification in at least 3 frameworks, and now it 
paradoxically does not play well with the framework from the same author.

A comprise would be to expose the template configuration so that users can
choose a loader, exactly the way Armin wanted Jinja to be used, no 
constrictions.

Thanks
___________________________________________________________
Neu: WEB.DE De-Mail - Einfach wie E-Mail, sicher wie ein Brief!  
Jetzt De-Mail-Adresse reservieren: https://produkte.web.de/go/demail02

[flack]

From:
Kenneth Reitz
Date:
2010-08-10 @ 20:20
Has anyone build an example large flask application architecture repository?

Kenneth Reitz
http://kennethreitz.com/contact-me

Re: [flask] [flack]

From:
Francisco Souza
Date:
2010-08-10 @ 23:24
Something like this: http://bitbucket.org/danjac/newsmeme ?

Cheers,
Francisco Souza
Software developer at Giran and also full time
Open source evangelist at full time

English: http://www.franciscosouza.net
Portuguese: http://www.franciscosouza.com.br
Twitter: @franciscosouza
+55 27 3026 0264


On Tue, Aug 10, 2010 at 5:20 PM, Kenneth Reitz <me@kennethreitz.com> wrote:

> Has anyone build an example large flask application architecture
> repository?
>
> Kenneth Reitz
> http://kennethreitz.com/contact-me
>
>

Re: [flask] Render_template syntax

From:
Date:
2010-08-10 @ 08:07
Hi Armin,

Maybe something like this:

render_template('admin:list_items.html')
render_template('admin.list_items.html')


I would actually prefer something like this:

admin = Module(__name__, url_prefix='/admin')

The static path could be inferred from the "url_prefix" or passed 
explicitly as in:

admin = Module(__name__, url_prefix='/admin', static_dir="admin/media", 
template_dir="admin/templates")

app.register_module(main)
app.register_module(admin)

Then the Jinja2  ChoiceLoader comes into play, it defaults to the main 
applications template folder if the modules folder is not defined:

 loader = ChoiceLoader([
...     FileSystemLoader(admin.template_dir),
...     FileSystemLoader(main.template_dir)
... ])


Why not the physical path of the file on the system using the 
jinja2.FileSystemLoader() as a default? This is how I have used Jinja 
wiith other frameworks, which is just GREAT, I just love Jinja, I have 
used the same templates and paths with CherryPy, Circuits and Web2Py with 
out changing anything.

I hope this did not come off as a rant, I apologize if it did

Thanks 


----Ursprüngliche Nachricht-----
Von: Armin Ronacher <armin.ronacher@active-4.com>
Gesendet: Aug 10, 2010 8:48:59 AM
An: flask@librelist.com
Betreff: Re: [flask] Render_template syntax

>Hi,
>
>On 8/10/10 3:59 AM, nhytro-python@web.de wrote:
>> Is there a reason behind the syntax when modules are concerned?
>>
>> render_template('admin/list_items.html')
>I'm open to suggestions on alternative formats for the filename string. 
>  It has to be a single string because otherwise you are unable to 
>reference other templates from within Jinja2.  Two parameters are not a 
>possible solution.
>
>
>Regards,
>Armin
___________________________________________________________
GRATIS für alle WEB.DE Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de

Re: [flask] Render_template syntax

From:
Marco Adelfio
Date:
2010-08-10 @ 02:21
I tend to agree -- the '/' concatenation is very counterintuitive in
this context.  If I recall correctly, this was one of the things that
originally turned me off to django.

In any case, I'm sorry my first post here is on something I don't like
about Flask, which I otherwise love.  After years of frustration with
frameworks that are either too low-level or too "magical", Flask has
made me productive again!

Thanks,
Marco


On Mon, Aug 9, 2010 at 9:59 PM,  <nhytro-python@web.de> wrote:
> Is there a reason behind the syntax when modules are concerned?
>
> render_template('admin/list_items.html')
>
> This is a definitive stumbling block If one just jumps into Flask 
coding, because it is misleading, it looks like path on the filesystem. 
Would a keyword argument have not been better like
>
> render_template(template_root_dir = 'admin', 'list_items.html')
>
> CherryPy has something of the sort for its static files. In a web 
application that consists of several other smaller applications/modules 
one can set the the root directories of the static files separately for 
each application, this might help the slightly complicated structure that 
is needed in Flask for larger applications at the moment.
>
> Just my thoughts, I really like Flask and I might convert all my apps to
use it, my coding experience was just a little dampend when I did some 
testing today trying to code a truly pluggable app that can be re-used 
without much bolierplate code or configuration.
> ___________________________________________________________
> GRATIS für alle WEB.DE Nutzer: Die maxdome Movie-FLAT!
> Jetzt freischalten unter http://movieflat.web.de
>