Python + Django page redirect

后端 未结 10 1846
别那么骄傲
别那么骄傲 2020-11-28 02:20

How do I accomplish a simple redirect (e.g. cflocation in ColdFusion, or header(location:http://) for PHP) in Django?

10条回答
  •  一整个雨季
    2020-11-28 02:33

    Depending on what you want (i.e. if you do not want to do any additional pre-processing), it is simpler to just use Django's redirect_to generic view:

    from django.views.generic.simple import redirect_to
    
    urlpatterns = patterns('',
        (r'^one/$', redirect_to, {'url': '/another/'}),
    
        #etc...
    )
    

    See documentation for more advanced examples.


    For Django 1.3+ use:

    from django.views.generic import RedirectView
    
    urlpatterns = patterns('',
        (r'^one/$', RedirectView.as_view(url='/another/')),
    )
    

提交回复
热议问题