tags:

views:

47

answers:

1

I want to write url link in views, and then return to template.

views.py

for platform in platform_list:
    if (fail_case.platform==platform):
        html_front = "<a href=/home/%s/%s/%s>" % (build, run, fail_case.testResult_id)
        html_back = "</a>"
        brray.append(html_front + "X" + html_back)
    else:
        brray.append("")

below is the result(WIN7):

http://img9.imageshack.us/img9/6806/86730486.png

i want to let X be a link, but how can i write it in views.py?

+1  A: 

I strongly advise against sending HTML from views. Templates are better suited to do this.

It looks like X is not a "link" as your template is escaping HTML characters. Look up the documentation on how to avoid this. This documentation link shows one way to achieve this. Inside your template you can use the autoescape tag. Something like this:

{% autoescape off %}
    {{ template_variable }}
{% autoescape %}
Manoj Govindan
Wow! it works!!!thank you!!!I don't want to write HTML in my views, but since it is impossible set variables in template, i can't deal some forloop.Thanks you:)
Yuan
@Yuan: glad to help :)
Manoj Govindan
Shorthand is `{{ template_variable|safe }}`
Jordan Reiter
@Jordan Reiter: correct. Danke.
Manoj Govindan