我希望在html模板django中有一个登录API 的 URLS.PY
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 :(得分: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>