Static files configuration

19 views
Skip to first unread message

Yash Garg

unread,
Dec 18, 2019, 8:08:57 AM12/18/19
to Django users
I have to display a HTML page with its supporting css, js and images. So i create a template folder to put HTML in it then i create a static folder in which i create css, js and img folder and put related files into these folders.
then I configure the
Settings.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

MEDIA_URL = '/media/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATIC_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)


.html file 

{% load staticfiles %}
<link href="{% static 'css/style.css' %}" rel="stylesheet">

views.py

def Index(request):
return render(request,'Teenager Startup.html')

please help me where i'm not getting the point.

Kevin Dublin

unread,
Dec 18, 2019, 3:32:39 PM12/18/19
to django...@googlegroups.com
Hey, try this:

In settings:

# If running collectstatic
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

# make sure if you have multiple apps that you want to direct to specific location of static files
STATIC_DIRS = (
    os.path.join(BASE_DIR, '../apps/core/static'),
)

Finally if you're using Django 2.0+

In the html file:
{% load static %} 


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/68f02a87-1876-4d81-9cf7-daba5f9079ca%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages