2017-11-18 78 views
0

我有以下Django的REST API終點Django的模板URL不叫Django的REST API

url(r'^api/email-verification/(?P<pk>[0-9]+)/$', EmailVerificationApiView.as_view(), name="email-verified") 

和下面是我在哪裏應用此API來驗證用戶,即點擊之後下面Activate HTML模板鏈接,上面提到的API端點將被調用,並在後端用戶將flaged驗證,但與點擊的HTML按鈕,它不會調用API。

<body> 
      <tr> 
      <td class="button"> 
       <div><!--[if mso]> 
       <v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="http://" style="height:45px;v-text-anchor:middle;width:155px;" arcsize="15%" strokecolor="#ffffff" fillcolor="#ff6f6f"> 
        <w:anchorlock/> 
        <center style="color:#ffffff;font-family:Helvetica, Arial, sans-serif;font-size:14px;font-weight:regular;">My Account</center> 
       </v:roundrect> 
        <a href="{% url 'email-verified' user_id %}"> 
        Activate 
        </a> 
       </div> 
      </td> 
      </tr> 
<body> 

點擊Actvate按鈕後,它重定向我另一個頁面這給下面的語句

Redirect Notice 
     The page you were on is trying to send you to an invalid URL (http:///api/email-verification/103/). 

    If you do not want to visit that page, you can return to the previous page. 

。我是在Django相對較新,Django的休息api.Is有沒有其他特殊的方式來調用Django休息api在Django的模板url標籤?

在提,API是一個POST API和上面給出的HTML模板是一個電子郵件模板。

+0

我想這個答案可能會有所幫助:https://stackoverflow.com/questions/25345392/how-to-add -url-parameters-to-django-template-url-tag –

+0

我更新了我的問題。 – RTan

+0

什麼是''標籤 – Satendra

回答

-1

在模板中你有

{% url 'email-verified' user_id %} 

它應該是:

{% url 'email-verified' pk=user_id %} 
+0

href =「http://」的目的我不工作,我也更新了我的問題。點擊Activate按鈕後,它會將我的網頁重定向到一個頁面,這表明我正嘗試在無效url中重定向,例如http:/// api/email-verification/103 /'。它實際上是從一開始就發生的,對不起,我最初沒有給它。 – RTan

+0

在http://''部分:'http:/// api/email-verification/103 /' –

+1

之後,您在url中獲得了一個額外的'/'另外,在閱讀包含事實上,你的api期待'post':你如何期待一個帶有''鏈接的帖子?要提交帖子,你需要一個表單。而且您無法從郵件正文中提交帖子。 –