static templatetag: adding default argument blank

30 views
Skip to first unread message

Mohammad Etemaddar

unread,
Jan 20, 2019, 12:47:05 PM1/20/19
to Django developers (Contributions to Django itself)
in the conversion of HTML template to Django template, sometimes it is hard to find&remplce static paths.
In current Django template we should change for example this:

<link rel="stylesheet" href="css/w3.css">
to
<link rel="stylesheet" href="{% static 'css/w3.css' %}">

as you see we add two parts to the href:

<link rel="stylesheet" href="{% static 'css/w3.css' %}">

We can also do in this order:


(2) <link rel="stylesheet" href="{% static '' %}css/w3.css">

In this way, we need to do only one find/replace. But in the previous way, we should first do find/replace on beginning and then add "%}" to the end. Maybe with some find/replace on every suffix (jpg,jpeg,css,js,png...)
But in way (2) We need only one find/replace if we have one asset directory in template.
In this way, We can give the static function default value blank in order to put just {% static %}.

Adam Johnson

unread,
Jan 20, 2019, 1:16:39 PM1/20/19
to django-d...@googlegroups.com
I would be against adding this. Most text editors support a find-and-replace with regex option that would let you capture the asset path and place it within the {% static '' %} tag; additionally, you could always change your templates to include STATIC_URL globally and just do {{ STATIC_URL }} if you wanted to avoid using the static tag with the path to the asset.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/b891d179-a6da-4150-8ebd-a966e5af9567%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Adam

Mohammad Etemaddar

unread,
Jan 20, 2019, 1:21:59 PM1/20/19
to django-d...@googlegroups.com
You are right. This is a better option, {{ STATIC_URL }}.
Mohammad Etemaddar
 
  in  
Programming services: Python & Linux



Reply all
Reply to author
Forward
0 new messages