尽管加载了所有其他静态文件,但Django-tinymce仍未加载到Amazon S3上

时间:2019-05-23 21:22:52

标签: django amazon-s3 django-tinymce

我一直在使用本指南

https://www.codingforentrepreneurs.com/blog/s3-static-media-files-for-django/

开始为我的站点的静态文件使用S3。

我让TinyMCE在本地工作,但是一旦我开始使用S3来存储文件,这是唯一无法加载的部分,并且使用它的小部件也不会出现。

在Chrome开发工具控制台中,出现以下错误:

Failed to load resource: the server responded with a status of 403 (Forbidden)
tiny_mce.js?AWSAccessKeyId=A[ACCESKEY]&Signature=Ze0U3pre28m%2FD9x2ftvTQkXl0OI%3D&Expires=1558648014:1 

Failed to load: https://conucos-bucket.s3.amazonaws.com/static/assets/js/tiny_mce/plugins/autosave/editor_plugin.js

在S3上,我已在Bucket Public中公开了所有文件,并在TinyMCE中获得2个文件的访问被拒绝

static/assets/js/tiny_mce/plugins/media/langs/dv_dlg.js
/conucos-bucket/
static/assets/js/tiny_mce/plugins/searchreplace/langs/mk_dlg.js
/conucos-bucket/

其余的都成功了。

以下是我在settings.py中导入的配置文件

import datetime

AWS_GROUP_NAME = #REDACTED
AWS_USERNAME = #REDACTED
AWS_ACCESS_KEY_ID = #REDACTED
AWS_SECRET_ACCESS_KEY = #REDACTED

AWS_FILE_EXPIRE = 200
AWS_PRELOAD_METADATA = True
AWS_QUERYSTRING_AUTH = True

DEFAULT_FILE_STORAGE = 'conucos.aws.utils.MediaRootS3BotoStorage'
STATICFILES_STORAGE = 'conucos.aws.utils.StaticRootS3BotoStorage'
AWS_STORAGE_BUCKET_NAME = 'conucos-bucket'
S3DIRECT_REGION = 'us-east-1'
S3_URL = '//%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
MEDIA_URL = '//%s.s3.amazonaws.com/media/' % AWS_STORAGE_BUCKET_NAME
MEDIA_ROOT = MEDIA_URL
STATIC_URL = S3_URL + 'static/'
ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'

two_months = datetime.timedelta(days=61)
date_two_months_later = datetime.date.today() + two_months
expires = date_two_months_later.strftime("%A, %d %B %Y 20:00:00 GMT")

AWS_HEADERS = { 
    'Expires': expires,
    'Cache-Control': 'max-age=%d' % (int(two_months.total_seconds()), ),
}

AWS_QUERYSTRING_AUTH = True


这是我在使用TinyMCE的模板上的静态负载

    {% load static %}
    <script type="text/javascript" src="{% static "assets/js/tiny_mce/tiny_mce.js" %}"></script>
    <script type="text/javascript" src="{% static "assets/js/tiny_mce/textareas.js" %}"></script> 

如何获取TinyMCE?任何帮助都将不胜感激!

0 个答案:

没有答案