0

绝对的初学者在这里有一个绝对的噩梦,将一个小网站部署到 Heroku。为了达到这一点,我已经解决了许多问题,但现在我似乎遇到了另一面墙。我已将此作为向 Heroku 提出的支持票,但除非这是他们方面的问题,否则我怀疑他们是否会以明确的答案回复我。

我可以成功部署到 Heroku,但是,当打开我的网络应用程序时,我只能看到“内部服务器错误”字样来代替我的网站。我通过我的哨兵日志收到一个问题/错误,如下所示:

MESSAGE
ParamValidationError: Parameter validation failed:
Invalid bucket name "": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$"
EXCEPTION(most recent call first)App OnlyFullRaw
ParamValidationError
Parameter validation failed:
Invalid bucket name "": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$"
storages/backends/s3boto3.py in exists at line 478
    def exists(self, name):
        name = self._normalize_name(self._clean_name(name))
        if self.entries:
            return name in self.entries
        try:
            self.connection.meta.client.head_object(Bucket=self.bucket_name, Key=name)
            return True
        except ClientError:
            return False
    def listdir(self, name):
name    
'CACHE/css/cf136be60f95.css'
self    
<storages.backends.s3boto3.S3Boto3Storage object at 0x7fbe4b7f4e80>
compressor/base.py in output_file at line 321
        """
        The output method that saves the content to a file and renders
        the appropriate template with the file's URL.
        """
        new_filepath = self.get_filepath(content, basename=basename)
        if not self.storage.exists(new_filepath) or forced:
            self.storage.save(new_filepath, ContentFile(content.encode(self.charset)))
        url = mark_safe(self.storage.url(new_filepath))
        return self.render_output(mode, {"url": url})
    def output_inline(self, mode, content, forced=False, basename=None):
basename    
None
content 
'/*!
 * Material Design for Bootstrap 4
 * Version: MDB Free 4.4.5
 *
 *
 * Copyright: Material Design for Bootstrap
 * https://mdbootstrap.com/
 *
 * Read the license: https://mdbootstrap.com/license/
 *
 *
 * Documentation: https://mdbootstrap.com/
 *
 * Getting started: https://mdbootstrap.com/getting-started/
 *
 * Tutorials: https://mdbootstrap.com/bootstrap-tutorial/
 *
 * Templates: https://'
forced  
False
mode    
'file'
new_filepath    
'CACHE/css/cf136be60f95.css'
self    
<compressor.css.CssCompressor object at 0x7fbe4aadf240>
compressor/base.py in handle_output at line 310
    def handle_output(self, mode, content, forced, basename=None):
        # Then check for the appropriate output method and call it
        output_func = getattr(self, "output_%s" % mode, None)
        if callable(output_func):
            return output_func(mode, content, forced, basename)
        # Total failure, raise a general exception
        raise CompressorError(
            "Couldn't find output method for mode '%s'" % mode)
    def output_file(self, mode, content, forced=False, basename=None):
basename    
None
content 
'/*!
 * Material Design for Bootstrap 4
 * Version: MDB Free 4.4.5
 *
 *
 * Copyright: Material Design for Bootstrap
 * https://mdbootstrap.com/
 *
 * Read the license: https://mdbootstrap.com/license/
 *
 *
 * Documentation: https://mdbootstrap.com/
 *
 * Getting started: https://mdbootstrap.com/getting-started/
 *
 * Tutorials: https://mdbootstrap.com/bootstrap-tutorial/
 *
 * Templates: https://'
forced  
False
mode    
'file'
output_func 
<bound method Compressor.output_file of <compressor.css.CssCompressor object at 0x7fbe4aadf240>>
self    
<compressor.css.CssCompressor object at 0x7fbe4aadf240>
compressor/base.py in output at line 302
        if not output:
            return ''
        if settings.COMPRESS_ENABLED or forced:
            filtered_output = self.filter_output(output)
            return self.handle_output(mode, filtered_output, forced)
        return output
    def handle_output(self, mode, content, forced, basename=None):
        # Then check for the appropriate output method and call it
filtered_output 
'/*!
 * Material Design for Bootstrap 4
 * Version: MDB Free 4.4.5
 *
 *
 * Copyright: Material Design for Bootstrap
 * https://mdbootstrap.com/
 *
 * Read the license: https://mdbootstrap.com/license/
 *
 *
 * Documentation: https://mdbootstrap.com/
 *
 * Getting started: https://mdbootstrap.com/getting-started/
 *
 * Tutorials: https://mdbootstrap.com/bootstrap-tutorial/
 *
 * Templates: https://'
forced  
False
mode    
'file'
output  
'/*!
 * Material Design for Bootstrap 4
 * Version: MDB Free 4.4.5
 *
 *
 * Copyright: Material Design for Bootstrap
 * https://mdbootstrap.com/
 *
 * Read the license: https://mdbootstrap.com/license/
 *
 *
 * Documentation: https://mdbootstrap.com/
 *
 * Getting started: https://mdbootstrap.com/getting-started/
 *
 * Tutorials: https://mdbootstrap.com/bootstrap-tutorial/
 *
 * Templates: https://'
self    
<compressor.css.CssCompressor object at 0x7fbe4aadf240>
compressor/css.py in output at line 51
                ret = []
                for media, subnode in self.media_nodes:
                    subnode.extra_context.update({'media': media})
                    ret.append(subnode.output(*args, **kwargs))
                return ''.join(ret)
        return super(CssCompressor, self).output(*args, **kwargs)
__class__   
<class 'compressor.css.CssCompressor'>
args    
[
'file'
]
kwargs  
{
'forced': False
}
self    
<compressor.css.CssCompressor object at 0x7fbe4aadf240>
compressor/css.py in output at line 49
                    ret.append(subnode.output(*args, **kwargs))
compressor/templatetags/compress.py in render_compressed at line 107
        rendered_output = compressor.output(mode, forced=forced)
compressor/templatetags/compress.py in render at line 131
        return self.render_compressed(context, self.kind, self.mode, forced=forced)
Called from: django/template/base.py in render_annotated

我使用 django-cookiecuttter 作为我网站的基本模板。就在昨天,我阅读了针对 django-cookiecutter 提出的另一个内部服务器错误问题的单独问题,我希望它也可以帮助我(即使细节看起来不同),但我尝试从 css 文件中删除“min”但没有成功。

由于错误消息提到了存储和压缩器,这是否可能与 Django-compressor 相关或白噪声(我都安装了)?我已经考虑尝试离线编译查看此处的说明,但这可能已经过时了,因为我的网站在本地运行良好,如果我能提供帮助,我想避免不必要的编码。协助将不胜感激。

我正在使用带有 Python 3.6.2 和 Django 2.0.2 的 Windows。我的生产静态设置如下:

# Static Assets
# ------------------------
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# COMPRESSOR
# ------------------------------------------------------------------------------
COMPRESS_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
COMPRESS_URL = STATIC_URL
COMPRESS_ENABLED = env.bool('COMPRESS_ENABLED', default=True)

提前致谢。

更新:

我仍然看到内部服务器错误,但是,我确信这与我设置存储桶的方式有关。我已按照本教程添加 IAM 组和策略,但我一定做错了,因为我收到一条配置不正确的错误消息,其中包含以下详细信息:

Client error:An error occurred (403) when calling the HeadBucket operation: Forbidden

我在 AWS 中的政策如下(我已经尝试了几次迭代):

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "s3:ListAllMyBuckets",
                "s3:HeadBucket",
                "s3:ListObjects"
            ],
            "Resource": "*"
        },
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::mybucket/*",
                "arn:aws:s3:::mybucket"
            ]
        }
    ]
}

我的头发很快就用完了,因为我似乎正以惊人的速度把它拔出来。毫无疑问,这又是一个小学生的错误,所以感谢您花时间复习。

4

2 回答 2

0

回答我的“更新”和第二个问题。我从头到尾再次浏览了 AWS 教程,虽然我认为我做的和以前完全一样,但这次它似乎已经奏效了,因为我现在又遇到了另一个内部服务器错误 - 哦,高兴。我能想到的唯一感觉不同的想法是将策略分配给组,所以可能是我以前做的方式,我没有链接它。

在再次打扰大家之前,我将继续寻找这个问题的答案,但请不要惊讶地看到我很快回来......

于 2018-02-25T18:52:45.530 回答
0

错误消息表明您的 AWS S3 存储桶名称无效:Invalid bucket name ""。空名称无效。

在 cookiecutter-django 中,它是由这个设置定义的。

您需要在 AWS 中创建一个 S3 存储桶并DJANGO_AWS_STORAGE_BUCKET_NAME在 Heroku 上设置环境变量:

heroku config:set DJANGO_AWS_STORAGE_BUCKET_NAME='the-bucket-name'

编辑:

我不确定使用 Whitenoise + django-compressor + Heroku 有多少 cookiecutter-django 是最新的,但是在 django-compressor 的 repo 上打开了一个可能很有趣的问题。

于 2018-02-24T16:36:26.990 回答