In settings.py, I set the STATIC_ROOT as below:
STATIC_URL = '/static/'
MEDIA_URL = '/files/'
STATIC_ROOT = BASE_DIR / "staticfiles"
MEDIA_ROOT = BASE_DIR / 'uploads'
when running the command:
python3 manage.py collectstatic
it works perfectly in my local development environment, it created a folder staticfiles, then collected all the files as expected, but when deploying the code on digitalOcean, it gives the error that says:
......
for entry in os.scandir(path):
FileNotFoundError: [Errno 2] No such file or directory: '/home/kevin/myproject/static'
I set the path with BASE_DIR / 'staticfiles',
why it points to the BASE_DIR / 'static'
the path and folder: BASE_DIR / 'static' was use by
STATICFILES_DIRS = [
BASE_DIR / 'static'
]
got so confused, debug it for a couple of days, it works in my local machine but not in production. any help is appreciated, thank you in advance.
Related
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
I did run the python manage.py collectstatic code, and after that all the static files were collected in the static folder. but the static files needed for the syling of the admin panel are not working. Could you help?
settings.py
STATIC_URL = 'static/'
STATICFILES_DIRS = [
'Portfolio/static/',
'Portfolio/',
''
]
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
Comment out the STATIC_ROOT
I think your STATICFILES_DIRS is wrong change it to os.path.join(BASE_DIR, 'static')
Try to change STATIC_URL. for example: /Portfolio-Deployment-Folder/static/
Try to change localhost port for example:
python3 manage.py runserver 9000 or 7000
most probably problem of STATICFILES_DIRS
And finally a full example for STATIC in my personal project:
STATIC_URL = '/myproject/static/'
# STATIC_ROOT = BASE_DIR / 'static'
STATICFILES_DIRS = [
BASE_DIR / 'static'
]
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')),
)
I am creating django project so root directory doesn't have any static folder i have two static folder in two app admin_panel and project respectively but when i run python manage.py collectstatic its shows file or folder not found:
Note: virtualenv is a project folder not venv environment
FileNotFoundError: [Errno 2] No such file or directory: '/home/tbosss/Desktop/environment/virtualenv/myproject/static'
STATICFILES_DIRS = (
('admin_panel', os.path.join(BASE_DIR, 'admin_panel', 'static')),
('project', os.path.join(BASE_DIR, 'project', 'static')),
)
STATIC_ROOT = '/static'
i dont know what will be the value of static root because there two static folder inside my apps not at root location
Check if the BASE_DIR in settings.py points to your project base directory:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Now, based on your FileNotFoundError the static folder directory should be in the project base directory. So, the STATIC_ROOT should be:
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
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')