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')
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
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.
I've created a django project with some apps. Initially, I just had a single app and i had static files and templates in it. As my project grew, I added some other apps to the project which they are still accessing the statics files and templates from inside the main app. I wasn't giving much care to this problem until i tried to make a simple production and used collectstatic command. Seems i can collect my static files to the STATIC_ROOT directory but i can't access them in the templates. Here is my project structure:
shop/
-myshop(main app)
--statics
--templates
-(some other apps beside main app)
-shop(directory created by project containing settings.py, manage.py)
This is my relevant settings.py configurations:
BASE_DIR = Path(__file__).resolve().parent.parent
INSTALLED_APPS = [
...
'django.contrib.staticfiles',
...
]
STATIC_URL = '/static/'
STATICFILES_DIRS = [
BASE_DIR / 'myshop/static',
]
STATIC_ROOT = BASE_DIR / 'static'
After running collectstatic django creates the static directory in root of project but when i remove or rename the myshop/static i get static files 404 in runserver.
I dont know how to check {% load static %} resulting path in runtime to put more information here. Is there any debug routine to understand what's django backend doing?
Try this
STATIC_URL = '/static/'
STATICFILES_DIRS = [
BASE_DIR / "static",
]
STATIC_ROOT = BASE_DIR.parent / "static_cdn"
$ python manage.py collectstatic This command will copy all files from your static folders into the STATIC_ROOT directory.
You must write the names of the static folder and the static root folder diffrent.
To learn more https://docs.djangoproject.com/en/3.1/howto/static-files/#configuring-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')),
)
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')