4 Replies - 389 Views - Last Post: 09 January 2012 - 09:09 PM Rate Topic: -----

Topic Sponsor:

#1 hiddenghost  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 36
  • View blog
  • Posts: 599
  • Joined: 15-December 09

Iteration in templating libraries

Posted 03 December 2011 - 06:31 AM

I know there are libraries for python to print html.

How do they do the template iteration.

I'm probably gonna look at their code eventually.

Just wonderin if any dream in code people had any knowledge to start me out.

Some more specific questions.

Are the methods really complicated to do arbitrary iteration with python to produce html templates with content?

Are there already some python functions that could help with arbitrary iteration like this.

I'm thinking any list type input with any amount of lists.

This post has been edited by hiddenghost: 03 December 2011 - 06:27 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Iteration in templating libraries

#2 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 443
  • View blog
  • Posts: 792
  • Joined: 08-June 10

Re: Iteration in templating libraries

Posted 05 December 2011 - 08:04 AM

A simple way to start would be to use regular expressions in conjunction with eval.
Was This Post Helpful? 1
  • +
  • -

#3 hiddenghost  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 36
  • View blog
  • Posts: 599
  • Joined: 15-December 09

Re: Iteration in templating libraries

Posted 06 January 2012 - 09:15 PM

View PostMotoma, on 05 December 2011 - 09:04 AM, said:

A simple way to start would be to use regular expressions in conjunction with eval.



I had already considered this, but I thought they must be using something else because of the whole idea that using eval should be discouraged.
Was This Post Helpful? 0
  • +
  • -

#4 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 443
  • View blog
  • Posts: 792
  • Joined: 08-June 10

Re: Iteration in templating libraries

Posted 09 January 2012 - 07:56 AM

Eval is discouraged; it is dangerous when user input is fed to eval, and it needs to be compiled at runtime as it is encountered.

However, if you wanted to build a sufficiently powerful templating system without eval, you could use getattr() or dictionary indexes to evaluate variables.
Was This Post Helpful? 1
  • +
  • -

#5 hiddenghost  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 36
  • View blog
  • Posts: 599
  • Joined: 15-December 09

Re: Iteration in templating libraries

Posted 09 January 2012 - 09:09 PM

View PostMotoma, on 09 January 2012 - 08:56 AM, said:

Eval is discouraged; it is dangerous when user input is fed to eval, and it needs to be compiled at runtime as it is encountered.

However, if you wanted to build a sufficiently powerful templating system without eval, you could use getattr() or dictionary indexes to evaluate variables.


I suppose it would be ok to use eval() if the template was only producing output.

Other safer methods could be used to accept user input.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1