开发者

Interpolate in django?

I am rails developer and new to django. Is there anyway to interpolate like in rails ??

<a href="{% url upload-csv %}" works fine but开发者_JAVA百科

This doesnt work: {% if request.path == "url upload-csv" %}class="selected" {% endif %} in rails i wud hav request.path == "#{url upload-csv}"

My code is

<a href="{% url upload-csv %}" {% if request.path == "url upload-csv" %}class="selected" {% endif %} ><span>Upload CSV</span></a>" "/upload-csv/"


You need to use "as" statement in your url template tag to make it usable as a local variable

{% url upload-csv as the_url %}

Then you may use the_url:

<a href="{{ the_url }}" {% if request.path == the_url %}class="selected" {% endif %} ><span>Upload CSV</span></a>

But I see no easy way to interpolate complex cases...

If it's too complex, it should be computed in the view...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜