4

I have some trouble adding my CSS in my template using {{ STATIC_URL }}. The tag does not work inside the link markup, but works anywhere else. This:

{{ STATIC_URL }}

correctly translated into

/static/

, but

link(href="{{ STATIC_URL }}css/bla.css"

become

<link href="{{ STATIC_URL }}css/bla.css">

I use pyjade with Django. Anybody can help on this?


edit I found the answer: if you want to use static attributes, use '!=' instead of '='. Example:

link(href!="{{ STATIC_URL }}css/bla.css"
Taufiq Muhammadi
  • 352
  • 4
  • 12
  • I keep forgetting to use != for Jade template code I want to escape being rendered. This solved my problem. Thanks. – DrHall Feb 02 '14 at 23:51

2 Answers2

1

Finally I found an answer from here : https://github.com/SyrusAkbary/pyjade/issues/44

use link href=STATIC_URL + 'css/bla.css' or link href='#{STATIC_URL}css/bla.css'

In addition to this situation,I met some problems when I use jade to write for loop in the template.I used django template to instead jade's for loop.

CashLee李秉骏
  • 1,038
  • 1
  • 10
  • 23
0

You should use the proper static tag

{% static "file_to_include" %}

and load the static lib in your template.

BTW: Since there are no updates to pyjade and its successor recently was deleted from pypi, I took the liberty to revive it: https://github.com/kakulukia/pypugjs

Version 5.0.1 has fixed the incompatibility with recent Django versions.

Andy
  • 726
  • 2
  • 6
  • 15