simple comparison?

8 views
Skip to first unread message

MikeKJ

unread,
Jun 11, 2014, 9:39:15 AM6/11/14
to django...@googlegroups.com
        if userform.is_valid():
            name = userform.cleaned_data['name']
            email = userform.cleaned_data['email']
            username = userform.cleaned_data['username']
            password = userform.cleaned_data['password']
            orgs = Organisation.objects.all()

#            return render_to_response("userprofile/join_form.html", {'orgs': orgs, 'name': name, 'controls': controls, 'userform': userform, },context_instance=RequestContext(request))

            for x in orgs:
                if x.title == name:              
                    return render_to_response("userprofile/join_form.html", {'name': name, 'controls': controls, 'userform': userform, },context_instance=RequestContext(request))
                else:
                    raise NameError("Missed")

This bit ...     if x.title == name:   simple huh?

if I run the same in a shell,
 
>>> from directory.models import Organisation
>>> name = "ANORG"
>>>orgs = Organisation.objects.all()
>>>for x in orgs:
>>>    if x.title == name:
>>>        name

that works

if I uncomment the render to response and do it in the template,
  
    {% for x in orgs %}
        {% ifequal x.title name %}
             {{ x.title }}
        {% endifequal %}
    {% endfor %}

that works

but for the life of me I cant see why in the actual view it decides that there is no match and goes to the else, it shouldn't, it should find a match!!!
Reply all
Reply to author
Forward
0 new messages