我在Django中使用重定向將用戶發送到另一個頁面,但無法這樣做。重定向無法發送回覆
views.py
def func1(request):
if not request.user.is_authenticated():
return render(request, 'login/login/login.html')
else:
if request.method == "POST":
return redirect('base:func2')
return render(request, 'base/home/index.html')
def func2(request):
if not request.user.is_authenticated():
return render(request, 'login/login/login.html')
else:
if request.method == "POST":
....
return render(request,
'bla_bla_bla.html',
{'location': location})
elif request.method == 'GET':
print('COntrol is here')
some_details_form = SomeDetailsForm()
return render(request, 'some_url/index.html',
{'some_details_form': some_details_form})
urls.py
app_name = 'base'
url(r'^another_url/$', views.func2, name='func2'),
url(r'^some_url/$', views.func1, name='func1'),
基地的/ home/index.html的
<div class="button" onclick="clicked_it()">
<span id="forward"> Go Further </span>
</div>
index.js
function clicked_it() { $.post("/base/some_url/"); };
所以控制不會去FUNC2,因爲我可以看到打印語句輸出控制這裏但我沒有看到FUNC2能夠呈現的頁面中return語句。控制卡在哪裏?
你可能會更具體一點做什麼,因爲我是新開發的Web開發人員,並且很少或根本沒有JS知識 –
首先解釋你爲什麼擁有'clicked_it ()'功能,而不是普通的鏈接或按鈕。 –
我正在使用它將數據發送到用戶將在頁面上輸入的後端。 –