2016-07-09 2 views
-1

html 템플릿 django에 로그인하기위한 API가 필요합니다.
URLS.PYhtml 템플릿에 로그인하기위한 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

I 템플릿에 입력 태그의 이름을 추가하여 해결했습니다. 감사합니다.

 <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> 
관련 문제