On Wed, Jul 20, 2011 at 1:14 PM, ydjango <traderash...@gmail.com> wrote:
> Occasionally I see this error in my app, > > UnboundLocalError: local variable 'settings' referenced before > assignment > > I have in my views .py > > from django.conf import settings > ....other imports... > > def new_view(request): > if not request.user.is_authenticated(): > return HttpResponseRedirect(settings.ENV_URL) <-=== this > is where error is thrown. > ....... > > What could be the reason? How can I prevent from occurring. > > I am using django 1.1, python 2.5 and mod_wsgi > > If, later in your view function, you have an assignment to settings, something like settings = "abcde" then, when the Python parser first examines your function, it will classify settings as a local variable, regardless of whether it is imported above or not. Accessing that local variable before its first assignment will be considered an error, and Python will refuse to compile the function. To fix this, you should either put "global settings" at the top of your function (if you really do want to overwrite it), or remove the assignment to the 'settings' variable (if you don't), or change the name of the variable you assign to (if it was an accident). -- Regards, Ian Clelland <clell...@gmail.com> -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.