I have a problem with my template accessing my static folder.
{% load static %}
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Rami Wahdan Hotels</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
<link rel="stylesheet" href="{% static 'css/animate.css' %}">
<link rel="stylesheet" href="{% static 'css/owl.carousel.min.css' %}">
<link rel="stylesheet" href="{% static 'css/aos.css' %}">
<link rel="stylesheet" href="{% static 'css/bootstrap-datepicker.css' %}">
<link rel="stylesheet" href="{% static 'css/jquery.timepicker.css' %}">
<link rel="stylesheet" href="{% static 'css/fancybox.min.css' %}">
<link rel="stylesheet" href="{% static 'fonts/ionicons/css/ionicons.min.css' %}">
<link rel="stylesheet" href="{% static 'fonts/fontawesome/css/font-awesome.min.css' %}">
<!-- Theme Style -->
<link rel="stylesheet" href="{% static 'css/style.css' %}">
</head>
<body>
my structure is:
in settings.py i put:
STATIC_URL = 'static/'
it is not working…
what is wrong?
Spha
September 23, 2022, 8:22am
2
It shouldn’t be in that folder, I think you have it in the app folder, it needs to be in the project root directory I believe. So the “teacher site” folder I think. Or else change the path in settings for STATIC_URL
import os
STATIC_URL = '/websites/mysite/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
# you might have to collect static again after you make this change
python manage.py collectstatic
How are you running your application? Is this a test environment using runserver
, or is this a production environment?
What are your other static file-related settings? (STATICFILES_DIRS, STATICFILES_FINDERS, STATIC_ROOT)
See How to manage static files (e.g. images, JavaScript, CSS) | Django documentation | Django for the full list of things to check.
This is not necessary and generally not recommended. There is absolutely no need to associate your STATIC_URL
with the physical directory in which static files are stored.
Spha
September 23, 2022, 2:19pm
5
Fair enough - I was also thinking in my head it should probably be left alone as STATIC_URL = 'static/'
It looks like “mysite” is an app
@ rwahdan1978
this is the normal layout of a django project hierarchy
source:
Note: It is also normal to have a static
directory in an app.
See Settings | Django documentation | Django
1 Like
Thanks I put the static folder in the right place now it’s working.