我已经建立了一个Django站点,并收到了来自GoogleBot的警告,我认为它在我的URL上设置了一个测试参数(0)。0在我的数据库中是不存在的主键。
<WSGIRequest
path:/for_sale_detail/0/,
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKIES:{},
META:{u'CSRF_COOKIE': u'xxxxxxxxxxxxxxxxx',
'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_ENCODING': 'gzip,deflate',
'HTTP_CONNECTION': 'close',
'HTTP_FROM': 'googlebot(at)googlebot.com',
'HTTP_HOST': 'example.com',
'HTTP_USER_AGENT': 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',这是我的url.py,第一组数字是我的主键(下面的例子是数字2):
url(r'^for_sale_detail/(?P<slug>[-\w\d]+)/$', for_sale_detail, name='for_sale_detail'),在我的html文件中,ajax URL (用户交互后填充的动态内容)以这样的方式被调用:
var slug = '2-terrace-link-house';
for (abc < 10)
{
...
slug = new_url;
call_detail_page();
}
function call_detail_page()
{
var detail_page_url = "{% url 'for_sale_detail' '2-terrace-link-house' %}".replace ('2-terrace-link-house', slug);
$.colorbox({
iframe : true,
width : '1200px',
height : '600px',
href:detail_page_url
});
}我已经创建了sitemap.xml文件来指向所有有效的段塞地址,但是当GoogleBot爬行时,它会将"0“附加到我的URL段塞中。理想情况下,我希望所有详细信息页都被google索引并找到,因此我不希望将GoogleBot重定向到一个不存在的页面。
一个有效的URL是:
http://www.example.com/for_sale_detail/2-terrace-link-house谢谢
发布于 2014-11-21 04:18:13
如果项目存在,您可以检查for_sale_detail,如果不存在,可以返回HttpResponseNotFound或引发Http404异常。
https://stackoverflow.com/questions/27053211
复制相似问题