-1
我一直在試圖解決這個之前提到,但我不知道如何Django的 - 局部變量「秒」分配
我在那裏我得到secs
form role="form" action="" method="POST" >{% csrf_token %}
<br>
<input type="number" name="secs" min="0" max="999" maxlength="3" class="form-control no-spinners" placeholder="Programar...">
<br>
<button type="submit" id="btn-login" class="w3-btn w3-large w3-green" style="width:30%"> Aceptar </button>
</form>
的形式我views.py
def streaming(request):
if request.method == 'POST':
secs = request.POST['secs']
print secs
programarTiempo(secs)
messages.info(request, 'Iniciando streaming en...' + secs + ' segundos')
time.sleep(float(secs))
return redirect('streaming')
return render(request, "straming.html", {"secs":secs})
當我到了我的.html我得到了以下錯誤:
UnboundLocalError at /streaming/ local variable 'secs' referenced before assignment
在此先感謝!
如果request.method不是「POST」定義它,然後' secs'永遠不會被定義,所以當你嘗試調用render()時,你會得到錯誤。 –
是的,我知道這個部分,但是如果我在post方法之外定義了secs,我不會得到'secs'的正確值。' – User100696
'你從request.POST ['secs']'得到了值,其中_doesn' t request_method不是POST時。所以我不知道你可能期望得到什麼樣的價值...... –