我有一个settings.py文件,必须在其中添加以下白噪声代码。 Whitenoise只是为我的Django应用程序简化了静态文件的部署。
import socket
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = "/static/"
if socket.gethostname() =="your_laptop_hostname_goes_here":
DATABASES["default"]["HOST"] = "localhost"
DATABASES["default"]["PORT"] = docker_config.POSTGIS_PORT
else:
DATABASES["default"]["HOST"] = f"{docker_config.PROJECT_NAME}-postgis"
DATABASES["default"]["PORT"] = 5432
# Set DEPLOY_SECURE to True only for LIVE deployment
if docker_config.DEPLOY_SECURE:
DEBUG = False
TEMPLATES[0]["OPTIONS"]["debug"] = False
# ALLOWED_HOSTS = ['.your-domain-name.xyz', 'localhost',]
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
else:
DEBUG = True
TEMPLATES[0]["OPTIONS"]["debug"] = True
ALLOWED_HOSTS = ['*', ]
CSRF_COOKIE_SECURE = False
SESSION_COOKIE_SECURE = False
我还必须创建一个带有布尔变量的docker_config.py文件。我尝试使用以下命令将文件导入到settings.py中:
from geodjango import docker_config
运行后,我得到标题中描述的错误:
python manage.py migrations
我的项目文件夹如下:
答案 0 :(得分:0)
尝试替代
import socket
HOST = '127.0.0.1'
PORT = 5556
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
data = s.recv(1024)
print('Received', repr(data))
使用
from geodjango import docker_config