我是Google App引擎的初學者,並試圖通過Google App HelloWorld應用。重定向網址在使用templates時不起作用。無法在Google應用中獲取重定向工作引擎
self.redirect('/?'+urllib.urlencode({'guestbook_name':guestbook_name}))
它重定向,但應該顯示在urlbar準確URL像
http://localhost:8080/?guestbook_name=some_name
,而它顯示像
http://localhost:8080/?guestbook_name=
class MainPage(webapp2.RequestHandler):
def get(self):
guestbook_name=self.request.get('guestbook_name')
greetings_query = Greeting.all().ancestor(
guestbook_key(guestbook_name)).order('-date')
greetings = greetings_query.fetch(10)
if users.get_current_user():
url = users.create_logout_url(self.request.uri)
url_linktext = 'Logout'
else:
url = users.create_login_url(self.request.uri)
url_linktext = 'Login'
template_values = {
'greetings': greetings,
'url': url,
'url_linktext': url_linktext,
}
template = jinja_environment.get_template('index.html')
self.response.out.write(template.render(template_values))
class Guestbook(webapp2.RequestHandler):
def post(self):
guestbook_name = self.request.get('guestbook_name')
greeting = Greeting(parent=guestbook_key(guestbook_name))
if users.get_current_user():
greeting.author = users.get_current_user().nickname()
greeting.content = self.request.get('content')
greeting.put()
self.redirect('/?' + urllib.urlencode({'guestbook_name': guestbook_name}))
index.html文件貌似
<html>
<body>
{% for greeting in greetings %}
{% if greeting.author %}
<b>{{ greeting.author }}</b> wrote:
{% else %}
An anonymous person wrote:
{% endif %}
<blockquote>{{ greeting.content|escape }}</blockquote>
{% endfor %}
<form action="/sign" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form>
<a href="{{ url }}">{{ url_linktext }}</a>
</body>
</html>
你使用'redirect url在使用模板時不起作用是什麼意思? – aschmid00 2013-03-20 21:42:33
我已經更新了代碼,我無法在您更新的問題中使用它 – vaibhav1312 2013-03-20 21:53:58
仍然沒有任何關於您所問的問題。你在哪裏使用'self.redirect'? 「urllib.urlencode」的部分在哪裏? – aschmid00 2013-03-20 22:00:20