from django.http import HttpResponseRedirect from django.urls import reverse def my_view(request): # Redirect to a static URL return HttpResponseRedirect('/success/')
from django.http import HttpResponseRedirect from django.urls import reverse def my_view(request): # Redirect to a dynamic URL url = reverse('myapp:success', args=[1]) return HttpResponseRedirect(url)In this example, `reverse()` function is used to get a URL pattern by its name `myapp:success`. The `args` parameter contains the positional arguments to be substituted in the URL, in this case `[1]`. The request is then redirected to the resulting URL. Overall, the `django.http` package provides a rich set of classes to handle HTTP requests and responses in Django, including `HttpResponse`, `JsonResponse`, `FileResponse`, etc. In addition, the `HttpResponseRedirect` class is a useful tool to redirect requests to different URLs.