Skip to main content

Django Simple Attachments

基于Django的图片储存模块

Requirements

  • sorl-thumbnail 生成缓存图片
  • django-taggit 图片标签
  • djangorestframework API
  • django-extra-fields base64字段上传

Getting Started

Install Packages

$ pip install sorl-thumbnail
$ pip install django-taggit
$ pip install django-extra-fields
$ pip install djangorestframework
$ pip install django-simple-attachments

Update settings.py

INSTALLED_APPS = [
    ...
    'sorl.thumbnail',
    'taggit',
    'rest_framework',
    'attachments',
    ...
]

Update urls.py

from attachments.views import media_view

urlpatterns = [
    ...
    path('api/attachments/', include('attachments.urls')),
    re_path(r'^media/attachments/(?P<path>.*)(/?)?', media_view),
    ...
]

URL使用

支持url中对图片进行裁剪等操作, 模仿unslash

<img src="/media/attachments/0001.png?width=100&height=100" />

参数说明

详细缩略图生成说明请参考Pillow

  1. width, 图片最大宽度
  2. height, 图片最大高度
  3. crop, 裁剪形式
  4. quality, 质量

Fields

ImagePickerField

单张图片选择字段, 需使用webpack打包js文件

from attachments.fields import ImagePickerField

class Brand(models.Model):
    name = models.CharField(max_length=200)
    logo = ImagePickerField(blank=True, null=True)

MultipleImageField

多张图片选择字段, 需使用webpack打包js文件, 支持拖拽排序, ** 字段基于postgres的ArrayField, 所以必须使用postgres数据库 **

from attachments.fields import MultipleImageField

class Product(models.Model):
    name = models.CharField(max_length=200)
    images = MultipleImageField(size=4, blank=True, default=list)

字段效果 图片选择

RichTextField

基于tinymce的富文本编辑器, 支持图片上传

使用前请下载tinymce

$ cd static
$ bower install tinymce

使用

from attachments.fields import RichTextField

class Blog(models.Model):
    title = models.CharField(max_length=200)
    content = RichTextField(blank=True, null=True)

Webpack

module.exports = {
  entry: {
    image_picker: './attachments/components/image_picker.js',
    multiple_image: './attachments/components/multiple_image.js'
  },
  output: {
    path: path.resolve('./static/dist/'),
    filename: '[name].bundle.js'
  },
  module: {
    rules: [
      {test:/\.js$/, exclude:/node_modules/, use:{
        loader: 'babel-loader',
        options: {
          presets: [['@babel/preset-env', {'targets':{'node':10}}], '@babel/preset-react']
        }
      }}
    ]
  },
}

Next

  • 实时图片裁剪
  • 搜索
  • 标签筛选
  • 删除
  • 权限
  • 图片自动标签
  • 实时图片格式转换
  • 自动清理

Version

  • 0.2.0 优化图片选择操作, 增加右侧实时查看并编辑图片基础信息, 增加搜索, 标签筛选
  • 0.1.0 增加fields功能, 增加实时编辑功能

Metadata

Release files for django-simple-attachments 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-simple-attachments 0.2.3
File Size Uploaded Provenance Actions
django-simple-attachments-0.2.3.tar.gz 985.2 kB Without provenance Details for django-simple-attachments-0.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-simple-attachments 0.2.3
File Interpreter ABI Platform Actions
django_simple_attachments-0.2.3-py3-none-any.whl Python 3 none any Details for django_simple_attachments-0.2.3-py3-none-any.whl

Total release size: 2.0 MB

Release files / django-simple-attachments-0.2.3.tar.gz

Download URL django-simple-attachments-0.2.3.tar.gz
Size 985.2 kB
Tags Source
SHA-256 checksum
How to use checksums
46f34d7fa81e4612ce45872d69a8578fbed1f28455e268c90fbf7a3e489622c1
BLAKE2b-256 checksum
How to use checksums
38f860d894f31d5d8d2e9eace8b0bba5ec444a66e6c1a8e75a73ad519714082f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

Release files / django_simple_attachments-0.2.3-py3-none-any.whl

Download URL django_simple_attachments-0.2.3-py3-none-any.whl
Size 1.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
408af052f3b5dc649162a271537e7629494808b92ef28d142587c375640f088e
BLAKE2b-256 checksum
How to use checksums
c5433f229481d00e9572cf7775e067e30f052d13f44c2588a03749abe9d84860
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

Security for django-simple-attachments 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page