我在railway.app上部署了一个django应用程序。在开发中,我可以上传图像,但是当我转到已部署的应用程序并单击upload,它会导致服务器错误(500)。
以下是我的settings.py代码
STATIC_URL = 'static/'
# STATIC_ROOT = BASE_DIR / 'staticfiles'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
if 'XXX' in os.environ:
# Bucket config
AWS_STORAGE_BUCKET_NAME = 'xxx'
AWS_S3_REGION_NAME = 'xxx'
AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'
# Static and media files
STATICFILES_STORAGE = 'custom_storages.StaticStorage'
STATICFILES_LOCATION = 'static'
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'
MEDIAFILES_LOCATION = 'media'
# Override static and media URLs in production
STATIC_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/{STATICFILES_LOCATION}/'
MEDIA_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/{MEDIAFILES_LOCATION}/'html代码
<div>
<img src="{{user_profile.profile_img.url}}" alt="Profile Image">
</div>
<a href="{% url 'profile-image' user_profile.user user_profile.profile_uuid %}"</a>发布于 2022-11-06 15:07:24
我已经解决了这个问题。在生产中,我将debug改为true,这导致了视图逻辑中的确切错误。我得到了图像的绝对路径,它会抛出这个错误,所以我改变了这个逻辑,得到了解决这个问题的相对路径。
https://stackoverflow.com/questions/74307325
复制相似问题