1from django.shortcuts import redirect
2
3def my_view(request):
4 # ...
5 return redirect('some-view-name', foo='bar')
6
1from django.shortcuts import render, redirect
2
3def redirecting(request):
4 return redirect("https://codingtutz.com/")
1<form method="POST">
2 {% csrf_token %}
3 {{ form }}
4 <input type="hidden" name="next" value="{{ request.path }}">
5 <button type="submit">Let's Go</button>
6</form>
7
1from django.shortcuts import render
2
3def my_view(request):
4 # View code here...
5 return render(request, 'myapp/index.html', {
6 'foo': 'bar',
7 }, content_type='application/xhtml+xml')
8
1from django.http import Http404
2
3def my_view(request):
4 my_objects = list(MyModel.objects.filter(published=True))
5 if not my_objects:
6 raise Http404("No MyModel matches the given query.")
7