簡體   English   中英

用於在 html 模板中登錄的 API

[英]API for login in a html template

我想要一個用於在 html 模板 django 中登錄的 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)
]

api.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>

我通過在模板中為輸入標簽添加名稱來解決它。 謝謝

        <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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM