13

Completely new to coding, sorry for the simple questions. I'm getting this attribute error when running python manage.py collectstatic. I'm editing settings.py. I have Django 1.5.1 and Python 2.7.5. Any help is appreciated and thanks in advance (again).

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'

Now, of course I've never messed with posixpath.py.

here's the contents of settings.py(minus db info and such):

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

4 回答 4

12

你做错了。你不应该把你的代码用引号引起来。在这里观看应该如何

它应该是这样的:

STATICFILES_DIRS = (
    os.path.join(os.path.dirname(__file__), "static")
)

它也属于您的MEDIA_ROOT设置STATIC_ROOT

于 2013-07-29T19:06:14.720 回答
4

@克里斯

STATIC_ROOT 和 MEDIA_ROOTS 是绝对路径,它们不能是元组,因此不允许使用“,”(逗号),因此将绝对路径称为“/your/static/file/absolute/path”

希望这会有所帮助:)

于 2014-12-15T06:26:00.670 回答
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")
于 2016-05-16T17:53:36.317 回答
2

概括

如果您是 Django 新手(像我一样)并遇到这个问题,我建议您阅读这本书 Django 的两个勺子,特别是他们有一个 GitHub 模板,这里有一个很好的应用程序布局。特别是,您要查看:

  1. 他们在设置下的“ base.py ”文件,其中包含“STATIC_ROOT”、“MEDIA_ROOT”等的所有配置。
  2. 看看他们的设置如何匹配他们的文件夹结构(见下文) 两勺推荐设置

八叉树(可选)

附带说明一下,如果您使用 GitHub 作为源代码控制,我强烈建议您在此处获取这个名为 Octotree 的 Chrome 扩展程序。这使您可以查看任何 GitHub 存储库的文件夹布局。

八叉树扩展

于 2014-05-15T18:53:19.313 回答