Home > Software engineering >  redirect Django not working blank response
redirect Django not working blank response

Time:01-05

I tried using reverse, no issues there are in django and when i see the response it is simply blank

from django.shortcuts import render
from django.http import HttpRequest
from django.http import HttpResponse
from django.http import JsonResponse
from django.shortcuts import redirect
def Aviation (request):
    return render(request, 'Aviation/Aviationtest.html')
def SendInformations (request):
    #a lot of uninteresting code
    return redirect(reverse("Aviation"))

here's my urls.py file

from django.urls import path
from . import views

urlpatterns = [
path("", views.Aviation, name="Aviation"),
path("let_me_send_informations", views.let_me_send_informations, name="let_me_send_informations"),
path("Informations", views.Informations, name="Informations"),
path("SendInformations", views.SendInformations, name="SendInformations")
]

I tried using reverse, the complete path, not using reverse and i am sure the directories are set well

CodePudding user response:

From the docs:

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

Change it to:

redirect("Aviation")

CodePudding user response:

you could use the redirect() method without the reverse like this:

def SendInformations (request):
    #a lot of uninteresting code
    return redirect("Aviation")

checkout the docs to learn more: https://docs.djangoproject.com/en/4.1/topics/http/shortcuts/#redirect

  • Related