[Answered ]-How can i disable variable with locals()?

0👍

del acc

But it is better to use a code like this

from django.core.exceptions import ObjectDoesNotExist
try:
    acc = accounts.objects.get(twitterid=userid)
except ObjectDoesNotExist:
    <<when not found>>
else:
    accountcredit = acc.credit
    return render_to_response('twitter_auth/info.html', locals(), context_instance=RequestContext(request))

p.s. locals() is useful for creating small views, use context={}

2👍

Just don’t use locals(), create your own context dictionary and pass that on to the template.

context = {
    'accountcredit': whatever_data_you_want
}
return render_to_response('twitter_auth/info.html', context, context_instance=RequestContext(request))

Also, using locals() is generally a bad idea since you’re passing with everything that your function has defined as variables, which can lead some unexpected behaviour and is generally considered unsafe.

Leave a comment