Why is DATA_UPLOAD_MAX_MEMORY_SIZE not working? Django, TinyMCE text field
I have a
DATA_UPLOAD_MAX_MEMORY_SIZE = 209_715_200
FILE_UPLOAD_MAX_MEMORY_SIZE = 209_715_200
in settings. However, when im trying to add 5 images in a tinymce text field (the total weight of the images is > 2.5 mb) i'm getting error: Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.
How could i fix it?
settings.py
Django settings for mainApp project.
Generated by 'django-admin startproject' using Django 5.0.3.
For more information on this file, see
https://docs.djangoproject.com/en/5.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.0/ref/settings/
"""
from pathlib import Path
from django.contrib import staticfiles
from django.urls import reverse_lazy
from dotenv import load_dotenv, find_dotenv
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
load_dotenv(find_dotenv())
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ["SECRET_KEY"]
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ["olimpiadnik.pythonanywhere.com", "127.0.0.1"]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'storages',
'tinymce',
'mainApp',
'portfolio',
]
TINYMCE_DEFAULT_CONFIG = {
'cleanup_on_startup': True,
'custom_undo_redo_levels': 20,
'selector': 'textarea',
'theme': 'silver',
'plugins': '''
textcolor save link image media preview codesample contextmenu
table code lists fullscreen insertdatetime nonbreaking
contextmenu directionality searchreplace wordcount visualblocks
visualchars code fullscreen autolink lists charmap print hr
anchor pagebreak
''',
'toolbar1': '''
fullscreen preview bold italic underline | fontselect,
fontsizeselect | forecolor backcolor | alignleft alignright |
aligncenter alignjustify | indent outdent | bullist numlist table |
| link image media | codesample |
''',
'toolbar2': '''
visualblocks visualchars |
charmap hr pagebreak nonbreaking anchor | code |
''',
'contextmenu': 'formats | link image',
'menubar': True,
'statusbar': True,
}
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'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 = 'mainApp.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 = 'mainApp.wsgi.application'
# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/5.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/5.0/topics/i18n/
LANGUAGE_CODE = 'ru-ru'
TIME_ZONE = 'Asia/Yekaterinburg'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_URL = '/media/'
MEDIA_ROOT = Path(BASE_DIR).joinpath('media').resolve()
if os.environ.get("AWS_ACCESS_KEY_ID"):
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_S3_ENDPOINT_URL = os.environ.get("AWS_S3_ENDPOINT_URL")
AWS_STORAGE_BUCKET_NAME = os.environ.get("AWS_STORAGE_BUCKET_NAME")
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
LOGOUT_REDIRECT_URL = "/"
LOGIN_REDIRECT_URL = "/"
MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage'
if os.environ.get("PRODUCTION"):
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD")
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
DEFAULT_FROM_EMAIL = os.environ.get("DEFAULT_FROM_EMAIL")
SERVER_EMAIL = DEFAULT_FROM_EMAIL
EMAIL_ADMIN = DEFAULT_FROM_EMAIL
else:
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
DATA_UPLOAD_MAX_MEMORY_SIZE = 209_715_200
FILE_UPLOAD_MAX_MEMORY_SIZE = 209_715_200
views.py:
def edit_post(request, slug):
post = get_object_or_404(Post, slug=slug)
if request.method == "POST":
form = PostForm(request.POST, instance=post)
if form.is_valid():
post.author = request.user.profile
post.createdDateTime = timezone.now()
if post.title != form.cleaned_data["title"]:
post.slug = unique_slugify(post.title.lower())
if "thumbnail" in request.FILES:
post.thumbnail = request.FILES["thumbnail"]
post.save()
return redirect('profile-details')
else:
form = PostForm(instance=post)
return render(request, 'portfolio/edit_post.html', {'form': form})
html template:
{% load static %}
{% block title %}
<head>
<link rel="stylesheet" href="{% static 'css/edit_post.css' %}">
<meta charset="UTF-8">
<title>Новая публикация</title>
<script src="{% static 'js/tinymce/tinymce.min.js' %}"></script>
<style>
input[type="checkbox"] {
transform: scale(1.2);
}
</style>
</head>
{% endblock title %}
{% block content %}
<head>
{{ form.media }}
</head>
<body class="text-center">
<div class="main-block justify-content-center text-center">
<form method="POST" class="post-form" enctype="multipart/form-data">
{% csrf_token %}
<div class="row header-box">
<div class="col">
<img src="/static/img/Union.svg" alt="плюсик" height="50" width="50" class="plus">
</div>
</div>
<div class="row title-box mb-4">
<p class="text-black mb-0"><input class="input-name-post text-center" type="text" value="{% if form.title.value != None %}{{ form.title.value }}{% endif %}" name="title" placeholder="Заголовок публикации" required minlength="5"></p>
</div>
<div class="row box-text">
{{ form.text }}
</div>
<div class="box-img">
<label for="formFileSm" class="form-label">Обложка для публикации</label>
<input class="form-control form-control-sm" id="formFileSm" type="file" name="thumbnail">
</div>
<div class="confirm">
<div class="form-check form-switch">
<label class="form-check-label" for="flexSwitchCheckDefault">
<input class="form-check-input" type="checkbox"
id="flexSwitchCheckDefault" name="isThisRegistration">Добавить регистрацию?</label>
</div>
<button type="submit" class="btn btn-info">Опубликовать</button>
</div>
</form>
</div>
</body>
{% endblock content %}```
i've added two lines to settings:``` DATA_UPLOAD_MAX_MEMORY_SIZE = 209_715_200
FILE_UPLOAD_MAX_MEMORY_SIZE = 209_715_200```