I have a general question about the new Django 1.3 static file framework.
I really like the new Django staticfile functionality introduced in Django 1.3. Normally, I set STATIC_URL="/static/" and enter the {{ STATIC_URL }} template tag into my templates. It's great how the development server automatically serves up the static files and all of my content is served up as expected.
The {{ STATIC_URL }} would be substituted in the template and might serve up files like this...
example.com/static/css/master.css
example.com/static/images/logo.png
example.com/static/js/site.js
However, I'm working with a legacy site where the static media is mounted at the url root. For example, the path to the static urls might look something like this:
example.com/css/master.css
example.com/images/logo.png
example.com/js/site.js
It doesn't use the "static" url namespace.
I was wondering if there is a way to get the new staticfile functionality to not use the static namespace and serve the urls above, but still retain the benefits of the new staticfile framework (collectstatic, static files served by development server, etc). I tried setting STATIC_URL="" and STATIC_URL="/", but neither seemed to have the desired effect.
Is there a way to configure static files to serve static files without a namespace? Thanks for your consideration.
You can manually add extra locations that do not exist within the
static
directories within your project:urls.py
This will map the media for the DEBUG dev server. And when you are running your production mode server, you will obviously be handling these static locations from the web server instead of sending the request through to django.
why not keep the staticfiles functionality and simply use rewrites at the web server level to serve up the content.
for instance:
this would keep your project directory a lot cleaner and also make it easier to move your static directories around in the future, for instance to move to your STATIC_URL to a CDN.
This is how you set up your urls.py to serve both index.html and your other static files on / in Django 1.10 (while still being able to serve other Django views):
See this answer where I wrote a more complete explanation of such a configuration – especially if you want to use it for production.