完全不熟悉编码,对不起简单的问题。运行python manage.py collectstatic
时,我收到此属性错误。我在编辑settings.py
。我有Django 1.5.1和Python 2.7.5。任何帮助都表示赞赏,并提前感谢(再次)。
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 61, in isabs
return s.startswith('/')
AttributeError: 'tuple' object has no attribute 'startswith'
现在,我当然没有和posixpath.py
混淆。
这里是settings.py
的内容(减去db信息等):
MEDIA_ROOT = "os.path.join(os.path.dirname(os.path.dirname(__file___))", "static", "media"
MEDIA_URL = '/media/'
STATIC_ROOT = "os.path.join(os.path.dirname(os.path.dirname(__file__))", "static", "static-only"
STATIC_URL = '/static/'
STATICFILES_DIRS = (
"os.path.join(os.path.dirname(os.path.dirname(__file__))", "static", "static",
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
SECRET_KEY = 'xxxxxxxxx'
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'mvp_landing.urls'
WSGI_APPLICATION = 'mvp_landing.wsgi.application'
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(os.path.dirname(__file__)), "static", "templates",
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'south',
'join',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
答案 0 :(得分:11)
你做错了。你不应该用引号转换你的代码。 Watch here how it should be
应该是这样的:
STATICFILES_DIRS = (
os.path.join(os.path.dirname(__file__), "static")
)
它也属于您的MEDIA_ROOT
和STATIC_ROOT
设置。
答案 1 :(得分:4)
@克里斯
STATIC_ROOT和MEDIA_ROOTS是绝对路径,它们不能是元组,因此不允许使用“,”(逗号), 所以提到绝对路径为“/ your / static / file / absolute / path”
希望这会有所帮助:)
答案 2 :(得分:3)
STATIC_ROOT = os.path.join(BASE_DIR, "static_in_pro","static_root"),
请删除静态根
末尾的逗号STATIC_ROOT = os.path.join(BASE_DIR, "static_in_pro","static_root")
答案 3 :(得分:2)
<强>摘要强>
如果你是Django的新手(就像我一样)并遇到这个问题,我建议你查看Django的两个Scoops这本书,特别是他们有一个GitHub模板和一个很好的应用程序布局here。特别是,您想看看: