-2
from models import *


def info(request):
    yasin = "teksaas"
    if check_key(request):
        api = get_api(request)
        user = api.me()
        userid = user.id
        accounts=accounts.objects.filter(twitterid=userid)
        if accounts == 1:
            return render_to_response('twitter_auth/info.html', locals())
        else:

            registeracc=accounts(twitterid=412313,others='Hello im jsaon walker what your problem i cant unt')
            registeracc.save()
            return render_to_response('twitter_auth/info.html', locals()) 
    else:
        return HttpResponseRedirect(reverse('main'))


Error : local variable 'accounts' referenced before assignment

このコードを変更すると動作しますが、複数のインポート モデルは必要ありません

def info(request):
    yasin = "teksaas"
    if check_key(request):
                from models import *
        api = get_api(request)
        user = api.me()
        userid = user.id
        accounts=accounts.objects.filter(twitterid=userid)
        if accounts == 1:
            return render_to_response('twitter_auth/info.html', locals())
        else:
            from models import *
            registeracc=accounts(twitterid=412313,others='Hello im jsaon walker what your problem i cant unt')
            registeracc.save()
            return render_to_response('twitter_auth/info.html', locals()) 
    else:
        return HttpResponseRedirect(reverse('main'))
4

1 に答える 1

1

クラスのように変数に名前を付けないでください

accounts=accounts.objects.filter(twitterid=userid)

修正してみて、それが役立つかどうかを確認してください

from models import *
def info(request):
    yasin = "teksaas"
    if check_key(request):
        api = get_api(request)
        user = api.me()
        userid = user.id
        acc=accounts.objects.filter(twitterid=userid)
        if acc:
            return render_to_response('twitter_auth/info.html', locals())
        else:

            registeracc=accounts(twitterid=412313,others='Hello im jsaon walker what your problem i cant unt')
            registeracc.save()
            return render_to_response('twitter_auth/info.html', locals()) 
    else:
        return HttpResponseRedirect(reverse('main'))
于 2013-09-01T23:52:30.893 に答える