Thanks to Leonardo, Daniel and Charly this issue is resolved! Each of your
comments helped me.

I changed my views.py file filter statement:

FROM: name = Name.objects.filter(pk=my_**number).values_list('city',
flat=True)

TO: name = Name.objects.get(pk=number).name

And in my template I have the same code:

{{ name|safe }}

And now Green shows on my web page instead of [u'Green']!



On Fri, Oct 18, 2013 at 2:39 AM, Leonardo Giordani <
giordani.leona...@gmail.com> wrote:

> Andrew, I think that the view is missing something:
>
>
> def enter_name(request):
>
>     my_number = request.user.number
>
>     name = Name.objects.filter(pk=my_number).values_list('city', flat=T
> rue)
>
>     *data = {...}
> *
>
> *    return render_to_response('template.html', data,
> context_instance=RequestContext(request))*
>
>
> where data is a dictionary with the values you want to be available in
> your template. So, for the template you posted, you could write
>
>
>     data = {'name':name[0]}
>
>
> Here, you need to decide what you need to pass: why do you use filter()
> instead of get()? Do you need just one value or multiple?
>
> If you need to pass a list to the template just fill the dictionary
> accordingly, but follow Daniel's advice when rendering the list in the
> template.
>
>
> Regards,
>
>
> Leo
>
>
>
> Leonardo Giordani
> Author of The Digital Cat <http://lgiordani.github.com>
> My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
> page <https://github.com/lgiordani> - My Coderwall 
> profile<https://coderwall.com/lgiordani>
>
>
> 2013/10/17 Charly Román <chack14r...@gmail.com>
>
>> Have you tried used get instead filter?
>>
>> 2013/10/17 Daniel Roseman <dan...@roseman.org.uk>:
>> > On Thursday, 17 October 2013 19:30:09 UTC+1, Andrew Michael wrote:
>> >>
>> >> Hi,
>> >>
>> >> I am new to Django and need some help. My issue is on my web page the
>> data
>> >> is showing up like this: [u'Green'] and I want it to only show Green -
>> >> without the unicode wrapping. Can you please explain why this is
>> happening
>> >> and how do I fix it?
>> >>
>> >> Here is my code.
>> >>
>> >> models.py:
>> >>
>> >> Class Name(models.Model):
>> >>
>> >> name = models.CharField(_('name'), max_length=100)
>> >>
>> >> number = models.ForeignKey(Number)
>> >>
>> >> views.py:
>> >>
>> >> def enter_name(request):
>> >>
>> >>     my_number = request.user.number
>> >>
>> >>     name = Name.objects.filter(pk=my_number).values_list('city',
>> >> flat=True)
>> >>
>> >> template.html:
>> >>
>> >> {{ name|safe }}
>> >>
>> >>
>> >>
>> >> Prints on the web page:
>> >>
>> >> [u’Green’]
>> >
>> >
>> > This nothing to do with Unicode. `name` is a *list*. So you have to
>> iterate
>> > over it:
>> >
>> >     {% for name in names %}
>> >         {{ name }}
>> >     {% endfor %}
>> > --
>> > DR.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Django users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> an
>> > email to django-users+unsubscr...@googlegroups.com.
>> > To post to this group, send email to django-users@googlegroups.com.
>> > Visit this group at http://groups.google.com/group/django-users.
>> > To view this discussion on the web visit
>> >
>> https://groups.google.com/d/msgid/django-users/f1d664fc-4a67-4d1f-8df5-76fda1bbef20%40googlegroups.com
>> .
>> >
>> > For more options, visit https://groups.google.com/groups/opt_out.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CABeWMUbaxazs1Sh0GMLhJVSXGcieUsTBhz2AgbWrhWD%2BBwru%3DQ%40mail.gmail.com
>> .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/A3kEL3CDydM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAEhE%2BOnHyuRMaoC8sKSs1wO6WiYZ8gzw1Y4AMGfJf_OwxTOE1w%40mail.gmail.com
> .
>
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJZ6upW8tmhSN2WhfwqjS99piKu4qa8MHPR_bVWM4GNd9y%2Bfww%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to