Этот вопрос закрыт для ответов, так как повторяет вопрос Почему происходит сброс текстовых файлов при перезапуске python воркера на heroku?

Удалаются картинки django на heroku?

После выполнения команд:
git add -a
git commit -m 'asd'
git push heroku master
И у всех записях(которые я сделал уже на залитом сайте) пропадают картинки.
Менял многие настройки в settings.py но всё безуспешно

settings.py:
"""
Django settings for Magazin project.

Generated by 'django-admin startproject' using Django 3.0.3.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import django_heroku
import os
import dj_database_url


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    "crispy_forms",
    'shop.apps.ShopConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'Magazin.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'Magazin.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
CRISPY_TEMPLATE_PACK = 'bootstrap4'
LOGIN_REDIRECT_URL = "/"
LOGOUT_REDIRECT_URL = "/"

django_heroku.settings(locals())


models.py:
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save, post_delete

class Basket(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    elements = models.ManyToManyField("BasketsItem")

def CreateBasket(sender, instance, **kworgs):
    try:
        new_b = Basket(user=instance)
        new_b.save()
        print('Basket was created!')
    except:
        pass
    else:
        pass

def DeleteBasket(sender, instance, **kworgs):
    try:
        new_b = Basket.objects.get(user=instance)
        new_b.delete()
        print('Basket was deleted!')
    except:
        pass
    else:
        pass

post_save.connect(CreateBasket, sender=User)
post_delete.connect(DeleteBasket, sender=User)

class BasketsItem(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    product = models.ForeignKey("Product", on_delete=models.CASCADE)
    num = models.IntegerField()

    def __str__(self):
        return f'{self.product}'    

class Product(models.Model):
    name = models.TextField()
    description = models.TextField()
    weight = models.IntegerField()
    price = models.IntegerField()
    category = models.ForeignKey("Category", on_delete=models.CASCADE)
    image = models.ImageField(upload_to='pics')

    def __str__(self):
        return f'{self.name}'    

class Category(models.Model):
    name = models.TextField()

    def __str__(self):
        return f'{self.name}'    
# asdss///m 
class Status(models.Model):
    name = models.TextField()

    def __str__(self):
        return f'{self.name}'
  • Вопрос задан
  • 218 просмотров
Ответы на вопрос 1
inoise
@inoise
Solution Architect, AWS Certified, Serverless
Heroku не хранит состояние своих контейнеров, поэтому если хочется хранить что-то из загрузок то делать это нужно на каком-нибудь другом сервисе
Ответ написан
Ваш ответ на вопрос

Вопрос закрыт для ответов и комментариев

Потому что уже есть похожий вопрос.
Похожие вопросы