what's different between {% static %} and {{ STATIC_URL}}

54 views
Skip to first unread message

老张

unread,
Jan 6, 2015, 6:29:58 AM1/6/15
to django...@googlegroups.com
hi,guys
i'm new to django。when I write my first app, there are 2 options to access static files,
1 using  {{ STATIC_URL}}
2 using  {% load staticfiles%} then {% static %}
what 's different between the 2 options, and ,when I migrate from development to production env
which one is conveniency ?
Thanks alot 
 


Andreas Kuhne

unread,
Jan 6, 2015, 6:56:12 AM1/6/15
to django...@googlegroups.com
Hi,

The difference is the age of the django project you are looking at. {% load staticfiles %} the {% static %} is the current way to load and use static files. It also has the option to do other things (like MD5 hashes for versions) automatically and should be used.

If you create a project in the new way, you will also get all of your static files nicely copied to a static file directory that you can serve from your webserver automatically. It's the best way to do it.

Regards,

Andréas



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/31d5812d.1eba0.14abefc5261.Coremail.paiis314%40163.com.
For more options, visit https://groups.google.com/d/optout.

Florian Schweikert

unread,
Jan 8, 2015, 4:16:29 PM1/8/15
to django...@googlegroups.com
On 2015-01-06 12:55, Andreas Kuhne wrote:
> The difference is the age of the django project you are looking at. {%
> load staticfiles %} the {% static %} is the current way to load and
> use static files. It also has the option to do other things (like MD5
> hashes for versions) automatically and should be used.

Also {% static %} works with your 500.html
As there is no context accessible if an 500 happen, {{ STATIC_URL }} is
not available.

-- Florian

Reply all
Reply to author
Forward
0 new messages