我在django做了一个网络应用。我试着把它部署在python manage.py collectstatic上,一切都很顺利,但最后,当我尝试用giving收集静态文件时,它给了我这个错误:
return database_name == ':memory:' or 'mode=memory' in database_name
TypeError: argument of type 'PosixPath' is not iterable提出一些想法,我该如何解决它。
这是我的setting.py文件
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '!25%rdt-$_$bsc*fl)e7x2*x6awjca^3_2t-k@l0tu*8k!f33&'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['*']
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
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',
},
]
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR / 'static/')发布于 2020-10-15 11:29:51
如果您使用的是DjangoV3.1,那么可以尝试在settings.py文件中的数据库路径周围放置str()。这是因为SQLite只接受字符串,而Django v3.1 settings.py返回一个pathlib.Path对象。
# settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': str(BASE_DIR / 'db.sqlite3'),
}
}我遇到了同样的问题,并在这里找到了答案:https://forum.djangoproject.com/t/django-tutorial-python-manage-py-startapp-polls-fails/2718
发布于 2020-12-24 17:20:45
#in settings.py do
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': str(BASE_DIR / 'db.sqlite3'),
}
}这里是问题所在,
BASE_DIR = Path(__file__).resolve().parent.parenttype(BASE_DIR)和type(BASE_DIR / 'db.sqlite3')都是<class 'pathlib.PosixPath'>
发布于 2020-10-04 00:16:10
也许你有一个打字错误,而不是',‘使用了'/’。STATIC_ROOT = os.path.join(BASE_DIR,'static')
https://stackoverflow.com/questions/64185724
复制相似问题