在过去的几天里,Googlebot 2.1开始点击我的某个网站,其中包含随机无效的分页值,例如/search/?page=nqfyvdhlopvyn
会返回页面错误。
通过电子邮件收到的Django错误信息
page = paginator.page(int(request.GET.get('page', 1)))
ValueError: invalid literal for int() with base 10: 'nqfyvdhlopvyn'
...
<WSGIRequest
path:/search/,
GET:<QueryDict: {u'page': [u'nqfyvdhlopvyn']}>,
POST:<QueryDict: {}>,
...
'REQUEST_URI': '/search/?page=nqfyvdhlopvyn',
导致错误的视图:
try:
page = paginator.page(int(request.GET.get('page', 1)))
except InvalidPage:
raise Http404("No such page of results!")
我不确定google来自哪些搜索字词,而且我很惊讶Django会返回错误,因为try:
应避免出现这类错误?