質問

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',
)
役に立ちましたか?

解決

You do it wrong. You shouldn't turn your code in quotes. Watch here how it should be

It should be like:

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

Also it belongs to your MEDIA_ROOT and STATIC_ROOT settings.

他のヒント

@chris

STATIC_ROOT and MEDIA_ROOTS are absolute paths and they cannot be tuples so no ","(commas) is allowed, So mention the absolute path as "/your/static/file/absolute/path"

Hope this will help :)

STATIC_ROOT = os.path.join(BASE_DIR, "static_in_pro","static_root"),

Please Remove the comma at end of Static root

STATIC_ROOT = os.path.join(BASE_DIR, "static_in_pro","static_root")

Summary

If you're new to Django (like I am) and run into this issue, I recommend looking over the book Two Scoops of Django's, in particular they have a GitHub template with a good app layout here. In particular, you want to look at:

  1. Their 'base.py' file under settings, which has all of the configurations for 'STATIC_ROOT', 'MEDIA_ROOT', etc.
  2. See how their settings matches their folder structure (see below) twoscoopsrecommendsettings

Octotree (Optional)

As a side note, if you use GitHub as source control, I highly recommend getting this Chrome extension called Octotree available here. This lets you view the folder layout of any GitHub repository.

octotree extension

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top