使用Django urls.py重定向301

时间:2015-01-27 16:37:17

标签: django django-urls

您好我正在为一些客户在网站上更改的网址设置301重定向。

我认为以下可能有效:

from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.views.generic import TemplateView, RedirectView


from cms.sitemaps import CMSSitemap

admin.autodiscover()

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^contact/', include('contact.urls')),
    url(r'^case-study/', include('casestudies.urls')),
    url(r'^contact-us/', include('contact.urls')),
    url(r'^news/', include('news.urls')),
    url(r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': {'cmspages': CMSSitemap}}),
    url(r'^', include('cms.urls')),
    url(r'^robots\.txt$', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')),
    url(r'^old-link/$', RedirectView.as_view(url='new-link/'), name='new-link'),
)

这似乎对我有意义,但这似乎不起作用。现在我对Django非常新,所以如果这是一个非常简单的查询,请道歉。

0 个答案:

没有答案