You can change the upload path of Django Froala Editor to Cloudinary by using Cloudinary's upload API. Here is an example of how to do this:
Sign up for a Cloudinary account and get your cloud name, API key, and API secret.
Install the Cloudinary Python library:
settings.py:
===========
pip install cloudinary
Add the following settings in your Django settings file:
import os
import cloudinary
import cloudinary.uploader
CLOUDINARY_CLOUD_NAME = "your_cloud_name"
CLOUDINARY_API_KEY = "your_api_key"
CLOUDINARY_API_SECRET = "your_api_secret"
cloudinary.config(
cloud_name = CLOUDINARY_CLOUD_NAME,
api_key = CLOUDINARY_API_KEY,
api_secret = CLOUDINARY_API_SECRET
)
In your Froala Editor view,
use the Cloudinary library to upload the image and return the URL to Froala Editor.
Here is an example view:
from django.http import JsonResponse
import cloudinary
import cloudinary.uploader
def froala_upload(request):
if request.method == 'POST' and request.FILES.get('file'):
try:
response = cloudinary.uploader.upload(request.FILES['file'])
return JsonResponse({
'link': response['secure_url']
})
except Exception as e:
return JsonResponse({
'error': str(e)
})
return JsonResponse({
'error': 'Invalid request'
})
5.
Add the URL for the Froala upload view in your URL configuration:
from django.urls import path
from .views import froala_upload
urlpatterns = [
path('froala_upload/', froala_upload, name='froala_upload'),
]
6.
In the Froala Editor options, set the imageUploadURL to the URL of your upload view.
Here is an example:
$('#froala-editor').froalaEditor({
imageUploadURL: '/froala_upload/'
});