0

setting before any change.

STATIC_URL = '/static/'

here I want to create one static files folder rather than assigning them to each every app by creating there name as directory and then I have to assign. So I want one common folder for all JS and Css which can be reflected in each and every template rather than defining all of them at different places.

1 Answer 1

2

firstly make below changes in your settings.py file :

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
os.path.join(BASE_DIR, "allfiles"),
]

Remember that allfiles is also folder in your project root. After that in your template load static files as given below: inside template.py:

{% load static %}
<html><script src="{% static 'index.js' %}"></html>
<--this file is in your common file you can replace it with any JS or CSS-->
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.