Remember that Django is "just" Python under the hood and that Python,
like any other self-respecting language, will always treat different
types as being, well, different!

On Sep 29, 10:14 pm, aa56280 <aa56...@gmail.com> wrote:
> Thanks for that. I figured it was something along those lines. I
> didn't think Django did a check on the type as well when evaluating
> the expression, but apparently it does. Very interesting.
>
> Thanks again.
>
> On Sep 29, 2:46 pm, Yo-Yo Ma <baxterstock...@gmail.com> wrote:
>
> > request.GET.get('subtopic') is returning a string, so your if
> > statement is roughly equivalent to:
>
> > >>> 1 == '1'
>
> > False
>
> > The sub_topic = int(request.GET.get('subtopic')) is the correct way to
> > do that. At first glance it seems like a lot of work, but if Django
> > tried to deserialize URL params automatically into Python objects
> > (like int), you would have all sorts of issues (like a "username"
> > being passed in as an int because a user decides to make their name
> > "1234", and so on).
>
> > On Sep 29, 12:52 pm, aa56280 <aa56...@gmail.com> wrote:
>
> > > I have in my template the following:
>
> > > {% if subtopic.id == selected_id %}...{% endif %}
>
> > > subtopic.id is being pulled from a list of subtopics that I'm looping
> > > over.
>
> > > selected_id is being sent to the template by the view after some form
> > > processing:
> > > #views.py
> > > selected_id = request.GET.get('subtopic', '')
> > > ...
>
> > > For some reason, my {% if %} statement in the template isn't getting
> > > evaluated even when the values of both subtopic.id and selected_id are
> > > the same. It does, however, work properly if I do the following before
> > > I send selected_id to the template:
> > > #views.py
> > > selected_id = int(selected_id)
>
> > > Why is this? I'm wondering.
>
> > > Thanks in advance for any insight.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.

Reply via email to