1

Django で Ajax によるセッションを開始する方法を知る必要があります。以下の説明とまったく同じようにやっていますが、うまくいきません! リクエストは正しく送信されますが、セッションは開始されません。ajaxなしで直接リクエストすればうまくいきます!何が起こっている?

'# URL

r'^logout/$', 'autenticacao.views.logout_view'

' # ログインのビュー

def login_view(request):

    username = request.GET.get('username', '')
    password = request.GET.get('password', '')

    user = authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            login(request, user)
            return HttpResponse(user.get_profile().sos_user.name)            
    return HttpResponse('user invalido')

'# HTML ページでの ajax

$(function(){

 $.get('http://localhost:8000/logout/?username=usuario?>&password=senha', function(data){
   alert(data);
 });
4

1 に答える 1

1

You're not calling the login_view. You're ajax request is going to the /logout/ url which is calling the autenticacao.views.logout_view.

Also, The ?> after username=usuario doesn't look right in the your get url.

My guess is you should be doing something like http://localhost:8000/login/?username=usuario&password=senha. (but I'd need to see your login url mapping to be sure).

Also, you should be POSTing the login information and using HTTPS for security reasons, but that's a different issue.

于 2010-07-17T01:34:59.060 に答える