开发者

Problems with handling queries to a css-styled mainpage of a GoogleApp when calling an imported class

开发者 https://www.devze.com 2023-03-12 21:00 出处:网络
I have this app.yaml file: application: ***** version: 1 runtime: python api_version: 1 handlers: - url: /static

I have this app.yaml file:

application: *****
version: 1
runtime: python
api_version: 1

handlers:
- url: /static
  static_dir: static
- url: /.*
  script: main.py

builtins:
- datas开发者_如何学编程tore_admin: on

And this main.py script:

import service
...
...
class UrlHandler(webapp.RequestHandler):
  def get(self):
    if self.request.query_string != '':
      service.MainPage()
    else:
      self.response.out.write(template.render('templates/main.html', {}))
...
...

Is it possible to do what I am trying to do? I want ...mainpage/ requests to land on the main html page with a css style sheet and ...mainpage/?... requests to be handled by the MainPage class in service called from main.py.


service.MainPage() isn't going to have access to the request and response objects that the framework has stuck on to the webapp.RequestHandler instance that get() sees.

You could pass self to service.MainPage() (assuming that's a function, and not a class that you're creating an instance of and them doing nothing with).

Or, even simpler, (and assuming that MainPage is a webapp.RequestHandler subclass), move the 'render templates/main.html on no query string' logic there, since it's only a few lines.

0

精彩评论

暂无评论...
验证码 换一张
取 消