Solved

Simple conditional in Kid template used with CherryPy

Posted on 2010-08-25
6
416 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 500 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
Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

 
LVL 17

Accepted Solution

by:
gelonida earned 500 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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

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 …
Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

632 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