STATIC_ROOT setup in Django 1.8

女生的网名这么多〃 提交于 2019-12-22 01:06:52

问题


I was tried n I can't set-up as per official documents... I am attaching IMG here, pls give me suggestions, Where is the problem.enter image description here

Or, give me simple steps for it with dictionary tree structure.

Thank you.

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

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


STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
    # '/var/www/static/',
)

回答1:


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




回答2:


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/')




回答3:


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')




回答4:


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')


来源:https://stackoverflow.com/questions/33851756/static-root-setup-in-django-1-8

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