Python Team Python Team - 11 months ago 81
Python Question

How to filter special characters in django template

I am trying to display ValuesQuerySet list to drop down list in django template page. I jus to filter special characters while displaying in drop down. I tried autoescape syntax but it doesn't work. Is anyother way to do this.


email_accounts = EmailAccount.objects.filter(user__user=self.request.user).values()
form.fields['account'].queryset = email_accounts.values_list('a_email')

Here the value should like [{'a_email': u''}, {'a_email': u''}, {'a_email': u''}].

In template page

{{ form.account }}

So it displayed like below in drop down list


I need to remove (u') those special chars when displaying in to drop down list. How to do that? any one suggest me.


You shouldn't be using a ValuesQueryset at all here. The queryset parameter for a ModelChoiceField expects, not surprisingly, a standard queryset.

email_accounts = EmailAccount.objects.filter(user__user=self.request.user)
form.fields['account'].queryset = email_accounts