web2py seems to be ignoring my html page and just displaying function varibles

36 views
Skip to first unread message

Andy W

unread,
Oct 3, 2019, 11:32:05 PM10/3/19
to web2py-users
I've been following a tutorial which is relatively simple, but for some reason the view doesn't seem to reflect my html file, it's probbaly something simeple but being new to web2py I can't see what I'm doing wrong - any help appreciated

Andy

This is my controller basics.py
# -*- coding: utf-8 -*-

import random
def isPrime(num):
    counter
= 2
   
while counter < num-1:
       
if num%counter==0:
           
return False
        counter
= counter + 1
   
return True

def random_number():
    x
= random.randint(3,20)
    result
= isPrime(x)
   
return locals()


This is my view random_number.html
{{extend 'layout.html'}}
<h1>Random Number</h1>
<h3>
    Is the random numnber, {{=x}}, prime?
</
h3>
<h3>
   
The answer is: {{=result}}
</h3>

This is my result:


This is what I am expecting:


Massimo Di Pierro

unread,
Oct 4, 2019, 12:43:27 AM10/4/19
to web2py-users
is the file in controllers/basic/random_number.html ?

Andy W

unread,
Oct 4, 2019, 5:34:15 AM10/4/19
to web2py-users
The basics.py file is in web2py/applications/pluralsight/controllers/

And random_number.html is in web2py/applications/pluralsight/views/


What I don't understand is other views seem to represent fine just this one?

I really like how quickly I could role out a web app with web2py but this is hampering me..

Andy W

unread,
Oct 4, 2019, 6:31:38 AM10/4/19
to web2py-users
It's like the function return locals is acting as print locals and overiding the html view, if I add another string as a variable that will show on the html view too..

villas

unread,
Oct 4, 2019, 7:17:10 AM10/4/19
to web2py-users
As Massimo implies,  your function is not finding your view,  so it is using a generic view instead.

Check carefully that your view is saved in the correct directory:  pluralsight/views/basics/random_number.html

Andy W

unread,
Oct 4, 2019, 7:29:30 AM10/4/19
to web2py-users
Thank you so much, on creation of the file I typed the filename rather than basics/filename

Working as expected now.
Reply all
Reply to author
Forward
0 new messages