Django static files not showing - django

I hav gone through my settings.py file to look at my static file setting
STATIC_ROOT = os.path.join(BASE_DIR,'static')
STATIC_URL = '/static/'
STATIC_DIR = os.path.join(BASE_DIR, 'static')
STATIC_ROOT = os.path.join(BASE_DIR,'static')
MEDIA_DIR = os.path.join(BASE_DIR, 'media')
but all my static files are nt showing when the page loads.
Please what could be going on
The static files where formerly working I do not know what i did that altered everything and I have gone through my settings file but found nothing wrong and the files are intact, it has not been changed

just remember to write at the top of the page
{% load static %}

There are are more than one static_root, possibly remove the static_root it looks same thing to static_dir

Related

What is the correct settings for static files in django

I just started using django and I got confused over the static files. As per this post correct static files setting I understand that STATIC_URL is just like the name. STATICFILES_DIRS is the place where django will look for static files and STATIC_ROOT where the static files will be collected to. For my project I had the following file sys
rest
|__ rest
|__ settings.py
pages
static
|__admin
|__images
|__vendor
|__bootstrap
templates
manage.py
I decided to go for a project based approach when having my folders instead of a per app one. Some stuff was not working with the website landing page I had and I saw that I needed to collectstatic and so I did but I set the path to my already existing static file which did not let me at first but somehow ended up working. Out of nowhere my static folder had admin on it which I assume is from the admin app that comes with django, and my project finally started to work properly which is the confusing part. I decided to follow the post and included in my settings the following
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles/')
Now I have a staticfiles folder along with my static folder. Also within the staticfiles folder I have everything I have in the static folder and that does not seem right and would like to know how to fix this. I am confused and a bit concerned that I will break everything again so any knowledge provided will be helpful.
I have used like this and its working fine:
STATIC_URL = '/static/'
STATICFILES_DIRS =[os.path.join(BASE_DIR, 'static')]
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
and use to implement code in the main Project urls.py and not in-app urls.py
urlpatterns += static(settings.STATIC_URL, documents_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, documents_root=settings.MEDIA_ROOT)

Django static files not loading properly

I tried to get my project set up with static files and I do not seem to be successful. I want a global static files instead of an in-app one and so my settings.py is
STATIC_URL = '/static/'
STATICFILES_DIRS =[os.path.join(BASE_DIR, 'static')]
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
And as such my directory is
The issue I face is that my vendor folders will not load. Only images do and my custom css file.
What I did is move animate.min.css to the css folder and it worked but I wonder if being inside many folders affects it.
root urls.py
urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')] # It will be deactivated when running collectstatic. Active on localhost
#STATIC_ROOT = os.path.join(BASE_DIR, 'static/') # It will be activated when running collectstatic. Active on server
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

ValueError: Missing staticfiles manifest entry even after collectstatic

I'm getting server errors because django can't find one of my static files even though I can see it in the folder:
ValueError: Missing staticfiles manifest entry for 'staticfiles\assets\img\icons\theme\communication\adress-book-2.svg'
I see the file sitting in this folder right here in both static and staticfiles:
static\assets\img\icons\theme\communication\
file path in template:
{% load static %}
<img src="{% static 'assets\img\icons\theme\communication\adress-book-2.svg' %}" alt="Confirmation Icon" class="icon bg-primary" data-inject-svg="data-inject-svg">
Running collectstatic doesn't have any effect. Any ideas?
Thanks!
EDIT: Forgot to add settings.py static settings:
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
DEBUG_PROPAGATE_EXCEPTIONS = True
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
First you should remove the lines that say :
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
And then you can keep the first 2 lines:
STATIC_ROOT = os.path.join(BASE_DIR, 'Folder') #either put static or staticfiles and then remove the other folder
STATIC_URL = '/static/'

django-inlinecss returns error You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path

I am trying to load a page as PDF. actually it loaded successfully - without any style or even the images. So I installed django-inlinecss and added it in installed_apps in settings.py and loaded it in template and called it as I was told. but it returns an error
You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
and points at:
1 {% load inlinecss %}
2 {% load static %}
3 {% inlinecss "css/style.css" %} <---
I don't have any idea how to fix it. Hope someone could help me in this
as the error say you have to specify the path of your static and media files in settings
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static")
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "media")
actually it worked when I set directory for STATIC_ROOT. but there is one thing to be noticed that you have to set another directory for that. Which means STATIC_URL and others like STATIC_FILE_ROOT, STATICFILES_DIRS shouldn't be the same as STATIC_ROOT
eg:
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
STATIC_URL = '/static/'
STATIC_FILE_ROOT = os.path.join(BASE_DIR, "static")
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
STATIC_ROOT = os.path.join(BASE_DIR, "static/assets")
sorry if that's not what you are looking for.

Static folder in the wrong subdirectory

I am new to Django and I am trying to setup a static folder for my project.
I am trying to place the static files in the following folder:
/portfolio-project/portfolio/static
I have made the following additions to settings.py:
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'portfolio/static/'),
]
STATIC_ROOT = os.path.join(BASE_DIR, '/static/')
STATIC_URL = '/static/'
However, after running collectstatic the static folder is created in: /portfolio-project/
You can customize STATIC_ROOT if you want to.
in your case
STATIC_URL = '/portfolio/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'portfolio/static/')