0

Django static directory name is set to static by default. Can it be changed to something else?. If i could change it to cssandjs could this bring any errors to my project? and does that also mean that in templates i would load static by {% load cssandjs %} instead of {% load static %}?

  • Does this answer your question? [django html template can't find static css and js files](https://stackoverflow.com/questions/66437690/django-html-template-cant-find-static-css-and-js-files) – Ivan Starostin Mar 25 '21 at 15:50
  • no it doesn't. My question was can i change the ```static``` directory name to something else so in templates it won't get presented as ```/static/css.css```. ```/static/``` comes to the path when you use the ``` {% static 'css.css' %}``` – zeuskedev 1 Mar 25 '21 at 15:59

2 Answers2

1

the statics files con also be loded from more than one directory, this can be defined by this setting, this is where django search your files inside your server

STATICFILES_DIRS = [
    BASE_DIR / "static",
    '/var/www/static/',
    '/some_folder/cssandjs',
    ]

thats why you put the files inside apps folder, to avoid overlapping

the url is defined by this setting, this is what you see on the web browser

STATIC_URL = '/static/'

in your template you always use {% load static %}, and django search in all your folders

https://docs.djangoproject.com/en/3.1/howto/static-files/

Guillermo Silva
  • 371
  • 2
  • 7
0

You can't change {% load static %} to {% load cssandjs %} because cssandjs is not a registered tag library. Instead, you can change the directory name (for example static to cssandjs) and the same for static_url='/static/' to '/cssandjs/'.

double-beep
  • 5,031
  • 17
  • 33
  • 41