Search code examples
djangopython-3.9django-static

Change Django static directory name


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 %}?


Solution

  • 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/