Django collectstatic command not finding and copying static files - django

I'm setting up my static files for Django to collect with this setup,
STATIC_URL = '/static/'
STATIC_ROOT = "127.0.0.1:8000/static/"
I made a static folder inside my app
my_app/static/my_app/my_css_framework_directory
My my_css_framework_directory contains the following directories, css, img, and js.
But when I ran python manage.py collectstatic, 0 files are copied?

STATIC_ROOT should be the absolute path to your static directory https://docs.djangoproject.com/el/1.10/ref/settings/#std:setting-STATIC_ROOT
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

Related

Django created staticfiles folder rather than static folder

I do not know why Django created a folder named staticfiles rather than static as expected. That might be the reason why I got an error after running python manage.py collectstatic:
The system cannot find the path specified: 'D:...\\static'
My settings file included:
from pathlib import Path
import os
import django_heroku
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
I had already tried to change 'staticfiles' to 'static' in STATIC_ROOT, but no success.
Could anyone please explain why and how to create a folder name "static"?
Thank you very much in advance!
I considered your static files are placed inside your app(s)
Try removing STATICFILES_DIRS so the setting will be:
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
...and try to re-run python manage.py collectstatic
Here is how collectstatic works:
First it collect static files from STATICFILES_DIRS if any, if there is no STATICFILES_DIRS in settings it collects static files from each app
Then placed them to STATIC_ROOT, so if your static files are placed inside your app(s) better to remove STATICFILES_DIRS
If still there is an error share your project structure

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')

Error deploying Django, unable to configure static files

I tried deploying Django project to www.pythonanywhere.com, My website ran but could not load static files.
I did collectstatic command in hosting server console but got error.
my project file configuration as follows
myproject # parent directory
-DjangoApp1 # an app inside project
-Myproject main file(includes manage.py etc)
-DjangoApp2 # an app inside project
-DjangoApp3 (in this app my static files located `DjangoApp3/static/DjangoApp3` )
in settings.py file
STATIC_ROOT = os.path.join(BASE_DIR, "/static/")
STATICFILES_DIRS = ('/DjangoApp3/static/DjangoApp3/',)
STATIC_URL = '/static/'
when I run collectstatic method in local machine ,below error occured
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\DjangoApp3\\static'
This works
STATIC_ROOT = os.path.join(BASE_DIR, "/static/")
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'staticfiles'),)
STATIC_URL = '/static/'
I've covered the three in an answer here before
Try this:
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
(os.path.join(BASE_DIR, 'static')),
)

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/')

heroku django not collecting my static files

My question is :
When i run collectstatic command staticfiles on heroku server my app didn't copied my staticfiles ?
my configuration :
**BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))**
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_in_env","static_root")
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static_in_pro","our_static"),
Django takes the static files from STATICFILES_DIRS and static folders inside installed apps into STATIC_ROOT.
You should check for sure that you have your static files inside your folder: BASE_DIR/static_in_pro/our_static.
The simplest way is to create a static folder inside your app and than put your static files inside it . In this case, you can ignore STATICFILES_DIRS.