My question: Can I simply ignore all of that nonsense of static, media, collectstatic and god knows what and simply link my css, img and my js files normally?
Take the admin files as for an example. I copied the templates into my projects template folder to edit them. Simple enough, but then when I wanted to change the css... Oh boy. I can't link any css files! Only css this template is willing to find is located in my django sources... Change that to anything (like href="/es/assets/css/admin.css") and it doesn't find it. I tried to edit the settings.py file and that static whatever thingy over there; this obviously didn't work.
Please help me: Excactly what do I need to write to my settings.py in order to have the following structure and to be able to link my files normally?
Gracias de antemano!
preguntado el 28 de agosto de 12 a las 12:08
How to override a static file
Imagine that you want to override
/static_url/admin/css/base.css. The first thing you have to do is find its location:
'admin/css/base.css' here: /home/jpic/env/lib/python2.7/site-packages/django/contrib/admin/static/admin/css/base.css./manage.py findstatic admin/css/base.css Found
Then, copy it to your
/srv/project/static_dir/, which you have added to
settings.STATICFILES_DIRS(see previous paragraph), for example:
mkdir -p /srv/project/static_dir/admin/css/ cp /home/jpic/env/lib/python2.7/site-packages/django/contrib/admin/static/admin/css/base.css /srv/project/static_dir/admin/css
Your copy would reside in
/srv/project/static_dir/tiene prioridad sobre
django/contrib/admin/static, because of the default order of
/srv/project/static_url/admin/css/base.cssto be a copy of your override
/srv/project/static_dir/admin/css/base.css, instead of the original
/srv/project/static_dir/is a dir listed in
Also, you will have to run collectstatic when you deploy.
Yes I wrote this article because I think it can help a lot of persons who would rather read a short article that only covers most common use cases rather than the complete documentation - ie. deadlines.
Espero que esto ayude.
Yes, you can ignore all of the in-built
Django machinery for static, media, etc. Although it really is convenient once you get a handle on it.
But if you do want to ignore it, and serve up the assets in your assets folder, there are two separate environments to consider:
In development, you can have the
Django runserver serve static assets just by telling it where to find them. Take a look at the docs aquí to see an example of using the
serve() función para hacer esto.
In production, you just need to configure your server to look in that directory for anything starting with
/assets/ en el capítulo respecto a la