Solved

Simple conditional in Kid template used with CherryPy

Posted on 2010-08-25
6
403 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
  • 4
  • 2
6 Comments
 
LVL 16

Assisted Solution

by:gelonida
gelonida earned 500 total points
Comment Utility
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
Comment Utility
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 16

Expert Comment

by:gelonida
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 16

Accepted Solution

by:
gelonida earned 500 total points
Comment Utility
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 16

Expert Comment

by:gelonida
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now