GAE: Error 404 when creating a new script

综合编程 2018-03-21 阅读原文

I'm using Google App Engine with Python environment.

I have my main code in the main.py file. I want to create a new .py file for a different page. I created the .py file, added the path to the yaml file. But I still get a '404 Error, resource not found'.

Here is my yaml file

application: myapp
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: .*
  script: main.app

- url: /hello
  script: hello.app

libraries:
- name: webapp2
  version: "2.5.2"

When the user goes to exampleurl.com/hello I want the hello.py file to be executed.

Here's the current content of hello.py

import webapp2

class HeyPage(webapp2.RequestHandler):
  def get(self):
      self.response.headers['Content-Type'] = 'text/html'
      self.response.out.write('Hello, All!')

app = webapp2.WSGIApplication([('/hello', HeyPage)],
                              debug=True)

Here is the log:

INFO     2014-01-10 06:15:31,150 module.py:617] default: "GET /hello HTTP/1.1" 404 154

You should list your handlers from most specific to least specific. Your handler:

- url: .*
  script: main.app

basically says that main.app
should handle every url. Since it is the first in the list, main.py
will try to handle every request regardless of the handlers that follow it in app.yaml
. Change it to:

handlers:
- url: /hello
  script: hello.app

- url: .*
  script: main.app

And all should work.

Hello, buddy!

责编内容by:Hello, buddy!阅读原文】。感谢您的支持!

您可能感兴趣的

Python3编写的CMS漏洞检测工具(含300POC)... *本文原创作者:六翼,本文属FreeBuf原创奖励计划,未经许可禁止转载 0×01 说明: 最近几年cms在网络空间中占比越来越多,...
Parallel request using multiprocessing.... I trying run parellel get requests using multiprocessing.dummy with report by pr...
Programiz: Python Global Keyword Before reading this article, make sure you have got some basics of Global, Local...
Ghacks Deals: The Ultimate Backend Developer Bundl... The Ultimate Backend Developer Bundle is a big eLearning bundle that inc...
Inside the Mind of a Neural Network with Interacti... Inside the Mind of a Neural Network with Interactive Code in Tensorf...