Redirect Django
from django.shortcuts import redirect
def my_view(request):
# ...
return redirect('some-view-name', foo='bar')
mohammed_samir
from django.shortcuts import redirect
def my_view(request):
# ...
return redirect('some-view-name', foo='bar')
LOGIN_REDIRECT_URL = 'home'
<form method="POST">
{% csrf_token %}
{{ form }}
<input type="hidden" name="next" value="{{ request.path }}">
<button type="submit">Let's Go</button>
</form>
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')
from django.shortcuts import render, redirect
def redirecting(request):
return redirect("https://codingtutz.com/")
from django.http import Http404
def my_view(request):
my_objects = list(MyModel.objects.filter(published=True))
if not my_objects:
raise Http404("No MyModel matches the given query.")