2016-07-09 42 views
-1

我想在html模板django中擁有用於登錄的API。
URLS.PY用於在html模板中登錄的API

from django.conf.urls import url 
from Average import views 
from Average.apis import * 

urlpatterns=[ 
    url(r'^add/fav/(?P<roll>[0-9]+)',add_fav), 
    url(r'^favs/',get_favs), 
    url(r'^auth/',authenticate) 
] 

apis.py

@api_view(['POST','GET']) 
def authenticate(request): 
    if request.method=="POST": 
     k = User.objects.all().filter(id=1) 
     serialized = UserSerializer(k,many=True) 
     return Response(serialized.data) 
     #I just returned the superuser id. To check if it is working. Forget         
     #it 

,最後我的HTML模板:
模板

<form method="post" class="right" action="/api/auth/"> 
       <input style="width:200px" type="text" class="form-control line"> 
       <input style="width:200px" type="password" class="form-control line"> 
       <button class="btn btn-primary line">Login</button></form> 

回答

0

我通過爲模板中的輸入標籤添加名稱來解決此問題。謝謝

 <form method="post" class="right" action="/api/auth/"> 
     <input style="width:200px" name="user" type="text" class="form-control line"> 
     <input style="width:200px" name="pwd" type="password" class="form-control line"> 
     <button class="btn btn-primary line">Login</button></form>