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-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment