I’ve read some documents related with static files but couldn’t make it work.
I’m using runserver on my computer for test purpose. My html is at this directory: C:\mytemplates\polls\t3.html. t3.html uses js and css files that were put under the my_static_files. So what should be the Django static settings, and where should the my_static_files be put?
I’ve read some documents related with static files but couldn’t make it work. I’m
Share
As you have not specified that exactly, i’m going to assume your static files are C:\my_static_files\
If so your settings should look like this:
In your template you can then use the {{STATIC_URL}} to load your static files:
If you have named the subfolders js and css different, change the links accordingly. If it still doesn’t work, check and doublecheck your leading and trailing slashes.
As you mentioned that using {{STATIC_URL}} does not return anything, i have to add this: to be able to use {{STATIC_URL}} you have to pass a RequestContext to your template. You can do this when returning a Response from a view by passing it a context_instance like this (ie.):