Skip to main content

上传图片组件

Project description

django-imgwidget

GitHub License PyPI Version

django-imgwidget is a Django package that provides easy and efficient image uploading in the admin site. It supports single-image uploads as well as batch uploads for multiple images. The package comes with features like large image preview, image deletion, and image rotation preview.

Features

  • Save as json or string to a field
  • Single-image and batch upload support.
  • Large image preview with the ability to delete images.
  • Image rotation preview for a better viewing experience.
  • Keyboard shortcuts for enhanced user experience.

Installation

Install the package using pip:

pip install django-imgwidget


-----
👍 后台上传图片

⚡️ 单图片、多图片批量上传

✨ 图片大图预览、删除

🐰 图片旋转预览

🔥 支持键盘快捷操作

    1.支持左右键切换预览图片
    
    2.支持ESC退出预览模式

🌈 效果图片

img_3.png

img_1.png!

Installation

pip install django-imgwidget

Homepage: https://pypi.org/project/django-imgwidget

Steps

  • Add django_imguploder to your settings.py

  • Configure the image upload route, route name is upload_image

path("upload", ImageUploadView.as_view(), name='upload_image')
  • Write a view function. Need to return JsonResponse image_list error_msg, if there are errors, return error_msg error prompt. example:
class ImageUploadView(views.View):
    def post(self, request):
        files = request.FILES or {}
        image_list = [upload_img(file) for file in list(files.values())]
        return JsonResponse({
            "error_msg": "",
            "image_list": image_list,
        })
  • Use the MultiImageField in admin.py
# models.py
class MyModel(models.Model):
    imgs = models.TextField(default=[], null=False, verbose_name='图片')
    description = models.CharField(verbose_name="描述", null="", max_length=100)
    
# admin.py  
class UploadImgsForm(ModelForm):
    imgs = MultiImageField(label="imgs", max_count=13, required=False)
    description_img = MultiImageField(label="description", max_count=1, required=False, save_json_list=False)


class CameraAdmin(admin.ModelAdmin):
fieldsets = [
    ('information', {'fields': (
        ('imgs',),
        ('description_img',),
    )}),
]
form = UploadImgsForm

# result: imgs -> '["1.jpeg", "2.jpg"]', description -> description_img.jpeg

Configuration:

accept:

config <input> accept

max_count:

Description: Defines the maximum number of files that can be selected/uploaded using the file input.

save_json_list:
Description: Determines whether the uploaded file names are saved as a JSON-formatted list or string.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-imgwidget-0.0.6.tar.gz (56.7 kB view details)

Uploaded Source

File details

Details for the file django-imgwidget-0.0.6.tar.gz.

File metadata

  • Download URL: django-imgwidget-0.0.6.tar.gz
  • Upload date:
  • Size: 56.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.1

File hashes

Hashes for django-imgwidget-0.0.6.tar.gz
Algorithm Hash digest
SHA256 a5efd4b996740ab32dab443de6617413fa8fba652bc8914c67fcc2918c16a47e
MD5 ace9361f1d8e69659fb66c56a4b0e8ba
BLAKE2b-256 69e19bd96acc9eca66d05bda4bb9a01bd8170d3dd46e02dd50f05ef9f6b47d68

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page