我在我的 Django 网站项目中本地提供了所有静态图像。我需要将它们托管在 AWS 上,以便我的 DEBUG = False 工作。我已经遵循了许多关于如何做到这一点的教程,但没有运气。我已经在下面发布了我的代码以进行最后的努力,希望这只是我错过的东西。我的 AWS 存储桶目前是公开的,因为这是我看到其他人在做的事情。任何帮助是极大的赞赏。谢谢!
设置.py
AWS_ACCESS_KEY_ID = 'hidden for privacy'
AWS_SECRET_ACCESS_KEY = 'hidden for privacy'
AWS_STORAGE_BUCKET_NAME = 'hidden for privacy'
AWS_S3_FILE_OVERWRITE = False
AWS_DEFAULT_ACL = None
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'America/Caracas'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
#STATIC_ROOT = os.path.join(BASE_DIR, 'static')
#MEDIA_URL = '/images/'
#MEDIA_ROOT = os.path.join(BASE_DIR, 'static/images/')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, '..','www','media')
HTML
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="shortcut icon" type="image/x-icon" href="{% static 'tab_icon.ico' %}">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="{% static "css/side.css" %}">
<link rel="stylesheet" href="{% static "css/style.css" %}">
<link rel="stylesheet" href="{% static "css/materialize.css" %}">
<link rel="stylesheet" href="{% static "css/front_page.css" %}">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body>
<nav class="blue hide-on-med-and-down banner">
<div class="nav-wrapper">
<a href="/front_page" class="header__name"><img src="{% static 'logo_name.png' %}"></a>
</div>
</nav>
</body>
我的存储桶结构是存储桶名称/图像/我所有的静态文件。
我的静态文件在本地提供时工作正常,但是当我将它们取下让 AWS 接管时,它们在屏幕上什么也没有显示,并且“检查”显示了一个小 url,指向它们应该在本地的位置,而不是来自 s3 和 AWS 的长用户。我对 AWS 很了解。感谢您的任何帮助!