本文介绍了以Webapp2中的状态码404作为响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序通过读取网址动态生成网页。例如,它会处理所有格式如下的URL:

  [url] / word 

如果 / word 是一个有效的URL,那么应用程序将生成一个页面并返回它背部。当应用程序找不到有用的东西时,它应该返回一个404页面。



我该怎么做?更具体地说,我该如何设置状态码为404?

解决方案

在RequestHandler中,您可以简单地调用 self.abort(404) webapp2.abort(404)来设置错误状态代码。



参考文献:



  • : / p>



My app is dynamically generating pages by reading the URL. For example, it will handle all URLs formatted like this:

[url]/word

If /word is a valid URL then the app will generate a page and return it back. When the app can't find anything useful it should return a 404 page.

How can I do that? More specifically how do I set the status code to 404?

解决方案

From within your RequestHandler, you can simply call self.abort(404) or webapp2.abort(404) to set the error status code.

References:

这篇关于以Webapp2中的状态码404作为响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 02:48