简体   繁体   中英

Django Redirect URLs to absolute url

I'm new to Django/Python and I'd like to redirect some URLS to another domain.

mydomain.com/blog needs to redirect to ' http://blog.mydomain.com '

How can I go about doing this?

from django.conf.urls import patterns, include, url

from django.views.generic.base import TemplateView

    urlpatterns = patterns('',
        url(r'^$',        TemplateView.as_view(template_name='pages/home.html'), name='home'),
        url(r'^blog/$',   TemplateView.as_view(template_name='pages/blog.html')),
 )

使用RedirectView通用视图

url(r'^blog/$', RedirectView.as_view(url='http://blog.mydomain.com')),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM