重定向Django不工作空响应

gg58donl  于 2023-01-06  发布在  Go
关注(0)|答案(2)|浏览(145)

我尝试使用反向,没有问题,有在django和当我看到的React,它只是空白

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"))

这是我的urls.py文件

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")
]

我尝试使用reverse,完整路径,而不是使用reverse,我确信目录设置良好

wgeznvg7

wgeznvg71#

来自文档:

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

将其更改为:

redirect("Aviation")
1hdlvixo

1hdlvixo2#

你可以使用redirect()方法而不需要反向操作,如下所示:

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

查看文档以了解更多信息:https://docs.djangoproject.com/en/4.1/topics/http/shortcuts/#redirect

相关问题