简体   繁体   English

GAE应用程序main.py请求处理程序

[英]GAE app main.py request handlers

I have been following a GAE/Jinja2 tutorial, and thankfully it incorporates a feature I have been struggling with within GAE, which is how to link the html pages using the main.py file so they can be edited using Jinja2. 我一直在关注GAE / Jinja2教程,并且值得庆幸的是,它结合了我一直在GAE中苦苦挣扎的功能,该功能是如何使用main.py文件链接html页面,以便可以使用Jinja2对其进行编辑。 The code for main.py is below. main.py的代码如下。

import webapp2
import logging
import jinja2
import os


jinja_environment = jinja2.Environment(
    loader = jinja2.FileSystemLoader(os.path.dirname(__file__) + "/templates"))

class MainPage(webapp2.RequestHandler):
    def get(self):
        template_values = {
            'welcome':'Welcome to my website!',


        }
        template = jinja_environment.get_template('homepage.html')
        self.response.write(template.render(template_values))

class FeedbackPage(webapp2.RequestHandler):
    def get(self):
        feedbackvalues = {

        }
        template = jinja_environment.get_template('feedbackform.html')

class TopFinishers(webapp2.RequestHandler):
    def get(self):
        template = jinja_environment.get_template('Top10Finishers.html')

class Belts(webapp2.RequestHandler):
    def get(self):
        template = jinja_environment.get_template('WWETitlesBelt.html')

class TopWrestlers(webapp2.RequestHandler):
    def get(self):
        template = jinja_environment.get_template('Top10Wrestlers.html')


app = webapp2.WSGIApplication([('/',MainPage),   ('/feedbackform.html',FeedbackPage),
('/Top10Finishers.html',TopFinishers),
('/WWETitlesBelt.html',Belts),
                              ],
                              debug=True)

Within the tutorial I followed the procedure for adding more request handlers and then instantiating them in the app object. 在本教程中,我按照添加更多请求处理程序,然后在app对象中实例化它们的过程进行操作。 However, when I load the page by clicking on the button on the page it takes me to a blank page. 但是,当我通过单击页面上的按钮加载页面时,将带我到空白页面。 When I click to go to 'Top 10 Finishers' it will successfully take me to the page as the URL is 'localhost:etc/Top10Finishers.html. 当我单击以转到“十大完成者”时,由于URL为“ localhost:etc / Top10Finishers.html”,它将成功将我带到该页面。

However, the content is not showing, do I need to add any URL handlers within the app.yaml file? 但是,内容未显示,我是否需要在app.yaml文件中添加任何URL处理程序?

application: 205semestertwo
version: 1
runtime: python27
api_version: 1
threadsafe: yes

    handlers:

    - url: /css
      static_dir: styling

    - url: .* 
      script: main.app

    libraries:
    - name: webapp2
      version: "2.5.2"
    - name: jinja2
      version: "2.6"

My question is 'What is causing this error'? 我的问题是“什么导致此错误”? As the console logs do not appear to be giving me any error or insight 由于控制台日志似乎没有给我任何错误或见解

You are successfully retrieving the new template on each handler, but forgot to write it on the response, the same way you did for your main handler: 您已成功在每个处理程序上检索了新模板,但忘记了在响应中编写它,就像对主处理程序所做的一样:

class TopFinishers(webapp2.RequestHandler):
    def get(self):
        values = {}
        template = jinja_environment.get_template('Top10Finishers.html')
        self.response.write(template.render(values))

This applies to all your handlers. 这适用于所有处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM