簡體   English   中英

如何從支付頁面重定向到索引頁面

[英]How to redirect from payment page to index page

付款后,我已將其重定向到成功頁面。

form action="success" method="POST"

視圖選項卡

def success(request):
    return render(request, 'success.html')

現在我希望頁面在一小段延遲后自動重定向到索引/主頁。

怎么可能達到。 有人可以幫忙嗎?

代替return render(request, 'success.html') ,使用return redirect('index')其中 index 是index的 url 的名稱。 確保在urls.py中有一個 url 用於indexpath('index',views.index,name='index')

我認為您可以通過在 javascript 中使用setTimeoutwindow.location.href來實現這一點。

使用time.sleep是這里的另一個選項,但這會使請求停止幾秒鍾,這可能會引發請求超時。

成功

def success(request):
    return render(request, 'success.html')

成功。html

<script>
function redirect () {
        var x = setTimeout(function () {
            window.location.href = "{% url 'index' %}";
            window.clearTimeout(x);     // clear time out.
        }, 5000);
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM