peterbe / django-static

Template tags for better serving static files from templates in Django
BSD 2-Clause "Simplified" License
193 stars 28 forks source link

Fix for development mode #14

Closed brutasse closed 13 years ago

brutasse commented 13 years ago

Hi Peter,

I just had an issue with django-static: I have

DJANGO_STATIC = False DJANGO_STATIC_MEDIA_URL = '/static/'

And in my html code, I do

<link rel="stylesheet" href="{% slimfile "css/style.css" %}">

With DJANGO_STATIC = True, the static url is added to the path. In dev mode, this is not the case. I just committed a fix that checks the presence of DJANGO_STATIC_MEDIA_URL. If it's here, it rewrites the path and prefixes DJANGO_STATIC_MEDIA_URL as the user would expect.

Otherwise, smooth experience with django-static :)

peterbe commented 13 years ago

Tricky. The point of setting DJANGO_STATIC=False is that it completely "walks away" from doing anything and it just returns exactly the same as was input. In your case, exactly "css/style.css" pure and simple.

The idea of setting DJANGO_STATIC=False is when you're debug/development mode and you want no optimization or anything fancy on your static resources.

peterbe commented 13 years ago

But I can see what you want to achieve. Because you can't do:

    src="{% staticfile "{{ STATIC_URL }}css/stryle.css" %}"

Also, I suspect your code would break a lot of people's environments. I for example have DJANGO_STATIC_MEDIA_URL=//ararvcafafr.cloudfront.net in my settings and I have to set two things to switch that off when in debug mode.

Perhaps a new variable for "people like you". Something like DJANGO_STATIC_MEDIA_URL_ALWAYS that does what your patch does. What do you think? If you change to that I'm happy to merge it in since it's harmless to existing users. Also, if you do that could you update the README as well?

brutasse commented 13 years ago

Ok, I think I'd rather fix my project than make you add a setting and more chances of potential misconfiguration ;)

I guess it's probably best to do {{ STATIC_URL }}{% staticfile "css/style.css" %} all the time and not use DJANGO_STATIC_MEDIA_URL at all, this way static files are served the same way regardless of the environment.

Closing the issue, if you don't mind :)

peterbe commented 13 years ago

The reason I added DJANGO_STATIC_MEDIA_URL was because I change all my html to just use staticfile and slimfile and there's only one place to change the media URL.