Forums

Having trouble with web.py templator

Hi All,

I am trying to create a simple webapp that uses web.py. I have a python script in my directory that should serve htmls from a 'templates' folder in the same directory. I used the manual configuration while creating the webapp and have uncommented the code that gets the app from my directory. I keep getting the error that its not able to find the template. Here is the syntax I am using template = web.template.render('templates')

class Logon: def GET(self): return template.Logon()

And the html file is named Logon.html Pretty simple but it keeps failing. Tried it with Jinja2 and it gave me the same error that I decided to use the templator instead , but to no avail. Any suggestions ? Thanks, Vikram

Hi Vikram,

That looks correct, but it is probably a path problem. You'll have to either put the directory containing the templates directory onto the path or use an absolute path to tell the application where your templates are.

Hi Hansel,

Thank you very much for the reply. I changed the path from 'templates' to '/home/vik1124/trackme/templates' . It seems to be working. But it appears to be a bit moody. It works sometimes and errors out other times. I realize this is a stupid thing to say. But I am assuming I am doing something wrong. Any advice ?

Thanks a lot, Vikram

Hi Hansel,

For some reason When I say o.path.abspath('templates') it gives me back '/home/vik1124/templates' which is not the same as the actual path '/home/vik1124/trackme/templates'. Thats where the problem was. Please ignore my previous post. Was doing something wrong there. Not I have it pointing to the right path and everything seems to be up and running. Thanks for the help.

Thanks and Regards, Vikram

Ah!

Yes os.path.abspath is a funny function. I think it uses the return value of os.getcwd. So it's basically like doing os.path.join(os.getcwd(), "templates"). Which might or might not be what you want depending on your current working directory.

Thats interesting to know ! Thanks for the help there. Its been fun creating my very first python web app. Hope to do more in the future. PythonAnywhere is a mondo cool idea by the way ! Way to go ! :)

Cheerio, Vikram

Thanks :-D

Hi Vikram and Hansel, I'm trying to figure out how to host web.py app as well -- I went through one of the web.py tutorials, so I have a code.py file and a Templates folder containing index.html. I can't figure out how to alter the initial ..._wsgy.py file to be able to run the web app, which already works fine when running on my own computer. Any hints would be appreciated! Does it have to do with changing these lines?:

app = web.application(urls, globals())
application = app.wsgifunc()

Thanks!

Hi ekofman -- looks like your app is up and running now, is everything working as far as you can see?

One thing -- I see that when I visit the app, I see an HTTPError with a 403 status. This is because it's trying to access another website from inside a web request, and the website that you're trying to access isn't on our list of whitelisted sites for free users. If the other site has a public API then I can add it to the whitelist -- just let me know what the site is.

Hi, yeah so I am using urllib2 to scrape a website's DOM in order to access campsite availability information from the parks and recreation site -- in order to do this do I have to pay for a subscription? thanks

Unless the site is on the whitelist of permitted sites then yes, you'll only be able to access it with a paid account. Whitelisted sites are typically only those with a public-facing API and which will be generally useful to a number of users.

But hey, it's worth a few dollars a month for an awesome service like PA, isn't it? (^_^)

Thanks, Cartroo :-)

@ekofman -- we normally only whitelist sites with a public API. But if you can point us to the site you want to scrape, we can consider whitelisting it.

Hi thanks for all your helpful and quick replies! And yes, it would definitely be worth paying, it's a very nice interface, but I just wanted to check for testing purposes whether I was even capable of getting something I already built to work on the site. The site is http://www.recreation.gov/, and more specifically its pages such as this one, which have camping information on them: http://www.recreation.gov/campsiteCalendar.do?page=calendar&contractCode=NRSO&parkId=70928&calarvdate=08/27/2013&sitepage=true&startIdx=26

ekofman,

I've sent you an email...