2017-03-31 2 views
0

PYTHON:djangoでautenticationと何かが欠けている?

from django.shortcuts import render 
from django.views import View 
from django.http import HttpResponse 
from django.contrib.auth import authenticate 

class Firstapp(View): 

    def get(self, request): 
     return render(request, 'index.html') 

    def post(self, request): 

     username = request.POST['your_name'] 
     user = authenticate(username=username) 
     return HttpResponse(user) 

HTML:

<form method="POST"> 
{% csrf_token %} 

<input type="text" name ='your_name' placeholder="username"/> 
<button type="submit">Button</button> 

私は多くのユーザー作成しています。admin、user_one、user_twoなどは/管理ページとユーザー名を経由してチェックがあります彼らがそうであるべきであるように。私はコードを書いたが、Djangoのドキュメントが続くが、なぜFistapp.postではデータベースにないユーザ名を返すのか分からない。 authnetication(username = 'user_one')のように、Noneを返します。あなたの助けに感謝します。

+2

パスワードが役立ちます。 – knbk

+0

Passowrdは必須ですか? –

答えて

1

あなたが認証するために、デフォルトDjangoのバックエンドを使用している場合、何を必要とすることは、パスワードなしで認証されている場合は、パスワードが

を必要とされるであろう、私はあなたがthis doc

持っている場合Djangoは常にNoneを返しますを読むことをお勧めします無効な認証