简体   繁体   中英

how to set static files directory in django

I am trying to get an existing django app up and running, but the css or any other static files are not showing up. I get the error:

"GET /static/css/mycss.css HTTP/1.1" 404 50

In the settings the following values are used:

DJANGO_ROOT = dirname(dirname(abspath(__file__)))
SITE_ROOT = dirname(DJANGO_ROOT)
STATIC_ROOT = normpath(join(SITE_ROOT, 'assets'))
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    normpath(join(SITE_ROOT, 'static')),
)

The app contains a directory called "static". It is in the current directory structure:

my-django-project > my-django-project > static > css > mycss.css

When I hit the home url via localhost, I get the above 404 error.

What am I doing wrong?

You need to run the collectstatic command to collect the static files in your apps to the STATIC_ROOT .

The command can be run like this:

python managy.py collectstatic

More information about static files can be found in the django documentation on static files .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM