2015-11-02 44 views
0

我一直在毆打我的腦袋,一直在解決這個問題。無法將參數從html傳遞到查看函數

我正在使用Django password_reset_confirm視圖來處理來自用戶的密碼更改請求。

我收到一個錯誤,如screenshot所示。

Reverse mismatch for 'password_reset_confirm' 

這是我的HTML呈現形式。

<div> 
    <h1></h1> 
    <form id='reset-password-form' action="{% url 'password_reset_confirm' uidb64=uidb64 token=token %}" method="post"> 
     {% csrf_token %} 
     {{form|foundation }} 
     {{title}} 
     {{validlink}} 
     <div id='submit-button'> 
      <input type="submit" id='submit-reset-form'> 
     </div> 
    </form> 
</div> 

URL映射是這樣的:

url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',password_reset_confirm, {'set_password_form':ResetPasswordForm,'template_name':'email/password_reset/password_enternew_password.html',} 
    ,name='password_reset_confirm') 

可有人告訴我,哪裏是錯誤?

回答

2

uidb64token沒有傳遞給模板上下文,因此您不能在url標記中使用它們。

最簡單的修復方法是從表單中刪除操作屬性。這將防止反向匹配錯誤,表單將提交到當前的url,這是正確的。

如果您查看主分支中django.contrib.admin應用程序附帶的password reset confirm template的代碼,則可以看到它沒有操作屬性。早期版本的Django有action="",但這在HTML5中是無效的。

+0

但password_reset_confirm以uidb64和令牌作爲參數,不應該從模板本身傳遞參數嗎? –

+0

根據文檔,password_reset_confirm可以從點擊的鏈接中獲取用戶信息,並給出一個很好的參考鏈接。 –

+0

對不起,我想我以前誤解了你的問題。看到我更新的答案。 – Alasdair