Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Simple conditional in Kid template used with CherryPy

Posted on 2010-08-25
6
Medium Priority
?
418 Views
Last Modified: 2012-05-10
I'm very new to CherryPy, but managed to get it running on FreeBSD.  Working great.  I started using the Kid template, as it is easier to implement than Cheetah, and I need only very basic functionality.  However, I've been unable to get any conditional (py:if) to work within the template.  Or more to the point, every conditional defaults to true apparently, or more likely the conditional is just not processed whatsoever.  

I've used the example from the following, but it doesn't work.....even if I may 5*6=2, it still shows the text.  http://kid-templating.org/language.html#conditionals-py-if

Any hints as to where I might be going wrong or if perhaps there is some configuration thing I need to do?
0
Comment
Question by:Xerc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 17

Assisted Solution

by:gelonida
gelonida earned 2000 total points
ID: 33524371
I don't know cherrpy and Kid template, but my suspicion is:


Use
if="5 * 6 == 2"

instead of
if="5*6 = 2"


== is used for comparisons
= should cause an error


0
 

Author Comment

by:Xerc
ID: 33524667
Sorry.  That was my typo in the question.  I double checked.  I did have comparison evaluator of == used.  

This is what I have in my template:   <p py:if="5 * 9 == 25">Math</p>  According to my understanding of Kid, "Math" should not be rendered / shown as 5 x 9 does not equal 25.  But it always shows up.  The Kid example from the page above is:  

<p py:if="5 * 5 == 25"> Python seems to be handling multiplication okay.</p>

I don't get how my syntax is different.

What's weird is that it appears Kid just isn't recognizing the py: portion, as when I look at the page source, py:if="5 * 9 == 25" appears within the <p> tag.  I know the Kid template otherwise works, as I'm passing it variables from CherryPy apps.  Very weird.
0
 
LVL 17

Expert Comment

by:gelonida
ID: 33524696
could you please lookwhat your web browser sees?
view the document as source.

What do you see?

DO you see:
<p py:if="5 * 9 == 25">Math</p>

or do you see?
<p>Math</p>
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 17

Accepted Solution

by:
gelonida earned 2000 total points
ID: 33524713
The question why I am asking is:
Do you have any proof, that kid-template is really running and active?

Do you have anything working from kids template (except passing code through tpo the browser)?

0
 
LVL 17

Expert Comment

by:gelonida
ID: 33524775
apologies Xerc

I should have read your reply in more detail. :-(


Does the example in the synopsis work?
(the one which should display the fruits)


0
 

Author Comment

by:Xerc
ID: 33525144
Ah.....I figured out the error.  In my one test template, I messed up the namespace which is associated with the py prefix.  I had xmlns:py="http://perl.org/kid/ns#".  To work it needs to be the correct ns of xmlns:py="http://purl.org/kid/ns#"  Very goof error on my part.  Perhaps a slip and wish to use Perl.  Heh.  
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"The time has come," the Walrus said, "To talk of many things: Of sets--and lists--and dictionaries-- Of variable kinks-- And why you see it changing not-- And why so strange are strings." This part describes how variables and references (see …
Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question