私は Django で初めて作業していますが、これまでのところ、エラーからエラーへとホッピングしており、自分が何をしているのかに本当に注意を払う必要があります。しかし、私をかなり悩ませてきたこの問題があります。
ブラウザに次のエラーが表示されます。
TypeError at /login/
login() takes exactly 2 arguments (1 given)
Request Method: POST
Request URL: http://127.0.0.1:8000/login/
Django Version: 1.6
Exception Type: TypeError
Exception Value:
login() takes exactly 2 arguments (1 given)
認証()およびログイン()関数を処理するviews.pyのコードを見ると、次のコードが得られます:
@cache_page(60 * 15)
def login_user(request):
context_instance=RequestContext(request)
if request.POST:
username = request.POST.get['username']
password = request.POST.get['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
state = "You're successfully logged in!"
else:
state = "Your account is not active, please contact the site admin."
else:
state = "Your username and/or password were incorrect."
return render_to_response('undercovercoders/index.html', {'state':state, 'username':username}, context_instance=RequestContext(request))
公式ドキュメントを使用して if/else ループを作成していましたが、定義されていないのはなぜですか? authenticate() が何も返さないからですか? Web サイトがエラー状態を返すということではないでしょうか? ご協力ありがとうございます。何か追加できることがあればお知らせください。
編集
私のurls.py
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.conf.urls.static import static
from django.conf.urls import *
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
(r'^/$','portal.views.index'),
(r'^$','portal.views.index'),
# Login / logout.
(r'^registration/$', 'portal.views.registration'),
(r'^login/$', 'portal.views.login'),
(r'^dashboard/$', 'portal.views.dashboard'),
(r'^team/$', 'portal.views.team'),
(r'^about/$', 'portal.views.about'),
(r'^parents/$', 'portal.views.parents'),
(r'^legal/$', 'portal.views.legal'),
(r'^index/$', 'portal.views.index'),