
Security News
Python Adopts Standard Lock File Format for Reproducible Installs
Python has adopted a standardized lock file format to improve reproducibility, security, and tool interoperability across the packaging ecosystem.
django-wysiwyg-image
Advanced tools
An easy way to paste images to wysiwyg editors in Django admin interface.
An easy way to paste images to wysiwyg editors in Django admin interface. All it needs from you is to upload an image through standard Django interface, and you will get a URL to provide to your wysiwyg editor.
Application was tested with Python 3.6 and Django 2.2, 3.2
Install using pip
...
pip install django-wysiwyg-image
Add 'wysiwyg_img'
to your INSTALLED_APPS
setting.
INSTALLED_APPS = [
...
'wysiwyg_img',
]
Usage:
Important! This tutorial does not cover basic Django configurations, installations of third party apps like django-tinymce, Pillow etc.
Let's imagine we have a posts
app in Django project with Post
model in which we want to paste images by wysiwyg editor in admin interface(in our case django-tinymce editor). First up we're going to import BaseImageModel
from wysiwyg_img.models
and inherite from it our PostImage
model. Then we have to tie PostImage
model to Post
model by ForeignKey
. Now our models.py
file should look like this:
from django.db import models
from tinymce import models as tinymce_models
from wysiwyg_img.models import BaseImageModel
class Post(models.Model):
title = models.CharField(max_length=100)
tiny_mce = tinymce_models.HTMLField()
class PostImage(BaseImageModel):
post = models.ForeignKey(Post, on_delete=models.CASCADE)
Run ./manage.py makemigrations
and ./manage.py migrate
.
Do not forget to install django-tinymce and Pillow before running migrations.
We also need to do some configurations in admin.py
file of current application:
from django.contrib import admin
from wysiwyg_img.admin import ImageInline
from posts.models import Post, PostImage
class PostImageInline(ImageInline):
model = PostImage
class PostAdmin(admin.ModelAdmin):
inlines = [
PostImageInline,
]
admin.site.register(Post, PostAdmin)
The last step is to create a superuser to access the admin interface. That's all! Now in admin interface we have fields to download unlimited images associated with Post
model. Each field has LINK TO PASTE
value to provide to your WYSIWYG editor. Just copy it and paste to the editor window. Pay attention! Editors may not include image plugins by default. Fields also have thumbnails and delete checkboxes for convenient way of managing images.
There are two possible configurations available through django.conf.settings
module.
WYSISWYG_IMG_UPLOAD_TO
Default: ''
String represents path to downloaded images under your MEDIA_ROOT
. It works exactly as FileField.upload_to.
Important! Every time you change this setting, you must run
makemigrations
andmigrate
command to create and apply migrations.
WYSISWYG_IMG_IMAGE_WIDTH
Default: 150
Integer represents thumbnail width in Django admin interface.
Neither django-wysiwyg-image
app nor Django itself removes images from your file system automatically when you hit the delete button. So you'll have to implement the removal of images yourself. Or you can use a brilliant app for that purpose: django-cleanup.
FAQs
An easy way to paste images to wysiwyg editors in Django admin interface.
We found that django-wysiwyg-image demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Python has adopted a standardized lock file format to improve reproducibility, security, and tool interoperability across the packaging ecosystem.
Security News
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.