Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django-尾部斜杠重置页面标题_Python_Django_Url_Trailing Slash - Fatal编程技术网

Python Django-尾部斜杠重置页面标题

Python Django-尾部斜杠重置页面标题,python,django,url,trailing-slash,Python,Django,Url,Trailing Slash,我为对这个问题的公然无知道歉,但我被指控在Django修复了一些我没有经验的东西 我们遇到了URL和重复内容的问题 如果我们访问“www.hello.com/services/”,那么我们可以得到完整的页面呈现,这是绝对好的 如果我们访问“www.hello.com/services”,那么我们会得到相同的内容,但默认设置似乎在一行中: class PageTitleNode(template.Node):? ? def render(self, context):?

我为对这个问题的公然无知道歉,但我被指控在Django修复了一些我没有经验的东西

我们遇到了URL和重复内容的问题

如果我们访问“www.hello.com/services/”,那么我们可以得到完整的页面呈现,这是绝对好的

如果我们访问“www.hello.com/services”,那么我们会得到相同的内容,但默认设置似乎在一行中:

class PageTitleNode(template.Node):?
 ?
    def render(self, context):?
        try:?
            meta_info = MetaInfo.objects.get(url=context['request'].path)?
        except ObjectDoesNotExist:?
            return u'This is our default page title'?
        return u"%s - hello.com" % meta_info.title
这方面的主要问题是,谷歌正在为两个几乎相同的页面编制索引,根据我们客户的付费过高的在线战略合作伙伴的说法,这是一个糟糕的SEO

我知道这是含糊不清的,但如果有人能帮上忙的话,我们会非常高兴的


谢谢你的阅读

我认为你的顾问是正确的。一个URL=一个资源。无论如何,在一个资源上有两个URL是相当肮脏的。这就是为什么Django具有从非尾随斜杠到带有尾随斜杠的URL的自动重定向功能。在下面

我非常肯定您的/services/的url定义regexp缺少尾部斜杠。无论如何,您应该只使用后面的斜杠

  • 确保从django.conf导入设置中设置为True
    ;打印设置。追加斜杠

  • 确保所有url正则表达式都有尾随斜杠,例如
    url(r'foo'…)
    坏的
    url(r'foo/'…
    )通过几乎没有,因为可能存在冲突,
    url(r'foo/$…
    )是好的

  • 确保所有MetaInfo对象都有带有尾随斜杠的url,例如
    MetaInfo.objects.exclude(url_uendswith='/')
    应在url中返回不带尾随斜杠的MetaInfo


  • 非常感谢你在这方面的建议-这不是我自己能够实现的事情,但我已经把它传递给了比我更有信心的人!我很高兴我能帮上忙-你也应该把上述建议转发给你传递给的人,以防对她/他有帮助。请