Code

Opened 6 years ago

Closed 6 years ago

#9330 closed (invalid)

Template params - list type

Reported by: Souparnika <nishakv@…> Owned by: nobody
Component: Uncategorized Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by mtredinnick)

Hi,

When I try to pass a list variable as one of template params from one of my view using render_to_response method in the view it is getting as a string data type.

View code -

ids = getIds(id,project_slug)-> returns a list type (eg: ids = [11111L,222222L]
template_params = {'ids':ids}
return render_to_response(template, template_params,
                              context_instance=RequestContext(request))

Then in the view.html

var ids = {{ ids }};

But here it is having problems since it is considering as string data type.

Any suggestions will be very usefull.

Thanks,
Nisha.

Attachments (0)

Change History (3)

comment:1 Changed 6 years ago by mtredinnick

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Unbreak description formatting (the preview button is your friend!).

What is the problem you are actually seeing here? Templates output strings, so there's no concept of a type in the output. What do you expect to see and what are you seeing? I suspect this is an incorrect expectation, rather than a bug, but if you could provide some more details that would be helpful.

comment:2 Changed 6 years ago by Souparnika <nishakv@…>

The problem is passing a list variable from a view to one of the template.
I am having a problem when it gets assigned to a javascript variable.

The line where it gets assigned var ids = {{ ids }};

I have copied below how it is getting rendered in the view and the error

ids = [1054652L];

Error - missing ] after element list

comment:3 Changed 6 years ago by mtredinnick

  • Resolution set to invalid
  • Status changed from new to closed

Ok, so this isn't a Django bug. Django's templates, if given no other information just display the Python unicode() form of the variable, which for something like a list means the repr() output. You need a filter to convert it to display as valid Javascript, for example.

Closing this, since it's not a bug. If you need more help, please ask on the django-users list.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.