Answer the question
In order to leave comments, you need to log in
Delete django images on heroku?
After executing the commands:
git add -a
git commit -m 'asd'
git push heroku master
And all the entries (which I have already made on the flooded site) lose pictures.
I changed many settings in settings.py but all without success
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())
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}'
Answer the question
In order to leave comments, you need to log in
Heroku does not store the state of its containers, so if you want to store something from downloads, then you need to do it on some other service
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question