Reputation: 1
Have a problem with connecting css to my template.
My project root is
"D:/birzha/", static path is "D:/birzha/static/"
, css
in
"D:/birzha/static/css/template.css"
.
What STATIC_ROOT
or STATICFILES_DIRS
should I use for correctly viewing css file? I tried so much turns, but nothing happens, css still off.
Upvotes: 0
Views: 1492
Reputation: 1649
First of all you need to tell where all your static files will be "collected", place the following lines in settings.py
:
BASE_DIR = (os.path.dirname(__file__))
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
Then you need to make a static
folder within your app
and the hierarchy
should be like this appname/static/appname/css
.
Finally run the command python manage.py collectstatic
and type yes
on prompt. This will copy all of your static files within a folder that you specified in STATIC_ROOT
Now you can access your static files by giving the path like,/static/appname/css/mystyle.css
Upvotes: 1
Reputation: 2645
You can try this Site root will contain you project root path. You can change "/templates" with static
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
# calculated paths for django and the site
# used as starting points for various other paths
TEMPLATE_DIRS = (
os.path.join(SITE_ROOT, 'templates/'),
)
MEDIA_ROOT = os.path.join(SITE_ROOT, 'templates/media/')
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(SITE_ROOT, 'templates/'),
)
Upvotes: 0