redirect djnago code example

Example 1: redirect django

from django.shortcuts import redirect

def my_view(request):
    # ...
    return redirect('some-view-name', foo='bar')

Example 2: redirect in dajango

from django.shortcuts import render

def my_view(request):
    # View code here...
    return render(request, 'myapp/index.html', {
        'foo': 'bar',
    }, content_type='application/xhtml+xml')

Example 3: redirect in dajango

from django.http import HttpResponse
from django.template import loader

def my_view(request):
    # View code here...
    t = loader.get_template('myapp/index.html')
    c = {'foo': 'bar'}
    return HttpResponse(t.render(c, request), content_type='application/xhtml+xml')

Tags:

Misc Example