Reputation: 119
I am writing a website with python and jinja2 in google app engine. My html page is showing this on the page:
Status: 200
Content-Type: text/html;
charset=utf-8
Cache-Control: no-cache
Content-Length: 432
Any idea where this problem is coming from? Also, why is {{ initial_city }} not displaying the results?
My main.py script is:
from google.appengine.ext import db
from google.appengine.api import memcache
from models import Deal
import os
import webapp2
import jinja2
#databasestuff
deal = Deal(title='Hello',
description='Deal info here',
city='New York')
deal.put()
print deal
jinja_environment = jinja2.Environment(autoescape=True,
loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__), 'templates')))
class MainPage(webapp2.RequestHandler):
def get(self):
template = jinja_environment.get_template('index.html')
self.response.out.write(template.render())
class DealHandler(webapp2.RequestHandler):
def get(self):
def get_deals(choose_city, update=False):
key = str(choose_city)
all_deals = memcache.get(key)
return all_deals
choose_city = self.request.get('c')
try:
initial_city = str(choose_city)
choose_city = initial_city
except ValueError:
initial_city = 0
choose_city = initial_city
template = jinja_environment.get_template('deal.html')
self.response.out.write(template.render())
class ContentHandler(webapp2.RequestHandler):
def get(self):
template = jinja_environment.get_template('content.html')
self.response.out.write(template.render())
app = webapp2.WSGIApplication([('/', MainPage),
('/deal', DealHandler),
('/content', ContentHandler)],
debug=True)
My html page:
<!DOCTYPE html>
<html>
<head>
<title>
Deallzz: Chosen City: {{ initial_city }}
</title>
</head>
...
Upvotes: 2
Views: 289
Reputation: 10526
To display initial_city, pass the variable to the template using the render method:
self.response.out.write(template.render(initial_city = initial_city))
Upvotes: 3
Reputation: 12986
Its the "print deal" that is causing the problem. Its being output before any response.write
Upvotes: 2
Reputation: 185530
This is just the headers of the HTML page. You should provide more informations/code of what you are trying now.
Upvotes: 1