Its my first project in django,so i dont know a lot of things.firstly, i want to serve static files from django STATIC_ROOT, not STATICFILES_DIRS. this is my project tree:
src >>
...db.sqlite3
...manage.py
...mainapp (main module)
...__init__.py
...settings.py
...urls.py
...wsgi.py
...myapp (django app)
...Migrations(Folder)
...__init__.py
...admin.py
...apps.py
...models.py
...tests.py
...views.py
...accounts (django app)
...Migrations(Folder)
...__init__.py
...admin.py
...apps.py
...models.py
...tests.py
...views.py
...templates
...myapp
...home.html
...accounts
...
...
...static
...myapp
...css
...bootstrap.css
...home.css
...js
...images
...accounts
...
...
...
...static_cdn (STATIC_ROOT)
...admin
...
...
...
...myapp
...css
...js
...images
...accounts
...css
...js
...images
in settings.py :
INSTALLED_APPS = [
'myapp',
'accounts',
.....,
.....,
.....,
'django.contrib.staticfiles',
]
.......
.......
.......
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR,'static'),
]
STATIC_ROOT = os.path.join(BASE_DIR,'static_cdn')
in urls.py :
from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
.......
from myapp.views import (
.......,
.......,
)
from accounts.views import (
.......,
.......,
)
urlpatterns = [
.......,
.......,
.......,
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
in home.html in templates :
<!DOCTYPE html>
{% load static %}
<html lang="en">
<head>
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1">
<title>.......</title>
<link rel="stylesheet" type="text/css" href="{% static 'myapp/css/bootstrap.css'%}"/>
<link rel="stylesheet" type="text/css" href="{% static 'myapp/css/home.css'%}"/>
</head>
<body>
.......
.......
.......
</body>
</html>
Then i run the command:
(clashsite) D:\DjangoSite\clashsite\src>python manage.py collectstatic
and following happens:
211 static files copied to 'D:\DjangoSite\clashsite\src\static_cdn'.
Now,the endpoint,what i want is : i dont want to serve my static files from 'static' folder in my tree, but from 'static_cdn' folder.more precise,i dont want to serve static files from STATICFILES_DIRS , but from STATIC_ROOT. But the content are served from only static folder.if i remove the static folder,static files are not served from static_cdn or STATIC_ROOT.How can i do that??