STATIC_ROOT setup in Django 1.8

和自甴很熟 提交于 2019-12-04 20:57:11

STATIC_ROOT = 'os.path.join(BASE_DIR, 'static_root', 'static') can't work.

Try this :

# define your base directory
# It will be `absolute/path/to/demo3`
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
STATIC_URL = '/static/'
# define where your static files will be collected
# It will be `absolute/path/to/demo3/static`
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# keep it empty for the moment
STATICFILES_DIRS = (
)

You have to understand STATICFILES_DIRS role :

Your project will probably also have static assets that aren’t tied to a particular app. In addition to using a static/ directory inside your apps, you can define a list of directories (STATICFILES_DIRS) in your settings file where Django will also look for static files.

I recommend you to read carefully Django docs : Managing static files

STATIC_ROOT should be without quotes:

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

Also, the STATIC_ROOT folder shouldn't be named the same as the STATICFILES_DIR folder, so you should name it something like staticfiles instead:

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles/')

STATIC_ROOT = 'os.path.join(BASE_DIR, 'static')' is a string which is wrong.

it should be STATIC_ROOT = os.path.join(BASE_DIR, 'static')

The error is clear in stating the STATIC_ROOT is not a filesystem path. Django requires that STATIC_ROOT be an absolute path to a folder location on the machine. This error likely means that your resulting STATIC_ROOT is a partial or relative path. What is the value of BASE_DIR? After the line that sets STATIC_ROOT and a print(STATIC_ROOT) to see what value it is.

Try setting BASE_DIR as follows:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Other Errors

On the line

STATIC_ROOT = 'os.path.join(BASE_DIR, 'static')'

You have the value surrounded by single quotes. os.path.join() is a function call. Remove the quotes and change the line like this:

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

Also, STATIC_ROOT cannot be included in the list of files in STATICFILES_DIRS. Consider setting the STATIC_ROOT folder to:

STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!