Google App Engine and 404 error

前端 未结 9 1250
一生所求
一生所求 2020-12-02 06:46

I\'ve setup a static website on GAE using hints found elsewhere, but can\'t figure out how to return a 404 error. My app.yaml file looks like

- url: (.*)/
           


        
9条回答
  •  生来不讨喜
    2020-12-02 07:13

    You can create a function to handle your errors for any of the status codes. You're case being 404, define a function like this:

    def Handle404(request, response, exception):
         response.out.write("Your error message") 
         response.set_status(404)`
    

    You can pass anything - HTML / plain-text / templates in the response.out.write function. Now, add the following declaration after your app declaration.

    app.error_handlers[404] = Handle404

    This worked for me.

提交回复
热议问题