K
K
Kamral Magaramov2020-10-17 14:04:28
Django
Kamral Magaramov, 2020-10-17 14:04:28

When to solve this problem: path = os.fspath(path) TypeError: expected str, bytes or os.PathLike object, not tuple?

I'm trying to collect all statistical files in pythonaanywhere :python3 manage.py collectstatic
After writing, I get an error path = os.fspath(path) TypeError: expected str, bytes or os.PathLike object, not tuple.

#settings
"""
Django settings for django_web_app project.

Generated by 'django-admin startproject' using Django 2.1.7.

For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings /

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""

import os
from pathlib import Path

# Build paths inside the project like this: os. path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATIC_ROOT= os.path.join(BASE_DIR, 'static'),

MEDIA_ROOT = os. path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

CRISPY_TEMPLATE_PACK = 'bootstrap4'

LOGIN_REDIRECT_URL = 'blog-home'
LOGIN_URL = 'login'

# Quick-start development settings - unsuitable for production
# See https:// docs.djangoproject.com/en/2.1/howto/deploy...

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '@5&-q%^[email protected]@[email protected]%b9yz^b#l-2)w&_s0ick#=wy3kw36$z($g'

# SECURITY WARNING: don't run with debug turned on in production !

ALLOWED_HOSTS = ['MusicLike.pythonanywhere.com']

# Application definition

INSTALLED_APPS = [
'blog.apps.BlogConfig',
'users.apps.UsersConfig',
'crispy_forms',
'django.contrib.admin',
'django.contrib. auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

#3d-party apps
'rest_framework',
# We also need to add an app authtoken,
# which generates tokens on the server.
'rest_framework.authtoken',
'rest_auth',
'allauth.account',
'allauth.socialaccount',
'rest_auth.registration',

]

#new
#

EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend'
SITE_ID=1

REST_FRAMEWORK={
'DEFAULT_PERMISSION_CLASSES':[
# do permission to view, update, delete entries
'rest_framework.permissions.IsAuthenticated',
],
# Why use both methods?
# The answer is that they serve different purposes.
# Sessions are used to power the browsable API
# and allow you to log in and out of it.
# We store the SessionAuthentication,
# since it's still needed for our peeking API, but now
# using tokens to pass authentication credentials
back and forth # in our HTTP headers.
'DEFAULT_AUTHENTICATION_CLASSES':[
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
]
}

MIDDLEWARE = ​​[
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django .middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'django_web_app.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth. context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'django_web_app.wsgi.application'

# Database
# https://docs.djangoproject.com/en/2.1/ref/settings...

DATABASES = {
'default': {
'ENGINE': 'django. db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}

# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings. ..

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]

# Internationalization
# https://docs. djangoproject.com/en/2.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

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

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

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

CRISPY_TEMPLATE_PACK = 'bootstrap4'

LOGIN_REDIRECT_URL = 'blog-home'
LOGIN_URL = 'login'

#wsgi

def application(environ, start_response):
if environ .get('PATH_INFO') == '/':
status = '200 OK'
content = HELLO_WORLD
else:
status = '404 NOT FOUND'
content = 'Page not found.'
response_headers = [('Content-Type', 'text/html'), ('Content-Length', str(len(content)))]
start_response(status, response_headers)
yield content.encode('utf8'

# To use your own django app use code like this:
import os
import sys
#
## assuming your django settings file is at '/home/MusicLike/mysite/mysite/settings.py'
## and your manage.py is is at '/home/MusicLike/mysite/manage.py'
path = '/home/MusicLike/Django_Web_App'
if path not in sys.path:
sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'django_web_app. settings'

# then:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dooMoob, 2020-10-17
@dooMoob

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question