Giter Club home page Giter Club logo

django-qiniu's Introduction

NOTE: This package is outdated and unmaintained, please take a look at other modern packages like django-qiniu-storage(https://github.com/glasslion/django-qiniu-storage), which uses a better appoarch by customizing django storage class.

django-qiniu

This package interages Qiniu cloud storage with Django framework. You must install qiniu's python-sdk before using this package.

Configuration

Add below lines in your django project's settings.py:

QINIU_ACCESS_KEY = 'your_key'
QINIU_SECRET_KEY = 'your_secret'
QINIU_BUCKET_DEFAULT = 'your_bucket_name'

How To Use

Use django-qiniu in your django project is very simple. First of all, your must copy django_qiniu directory to your PYTHON_PATH so you can import it.

1. Add Field To Your Model

To get started, you should add QiniuFileField or QiniuImageField to your models.py.

from django.db import models
from django_qiniu.fields import QiNiuImageField, QiniuFileField

def qiniu_key_maker_file(instance, filename):
    """

    Args:
    ~~~~~

    - instance, your model instance being saved
    - filename, original filename

    This function should return a string object which is the key of qiniu.
    """

def qiniu_key_maker_user_image(instance, filename):
    pass

class Photo(models.Model):
    qiniu_file = QiNiuFileField(upload_to=qiniu_key_maker_file, null=True)
    qiniu_image = QiNiuImageField(upload_to=qiniu_key_maker_image, null=True)

QiniuFileField's __init__ method receives some parameters:

  • upload_to, a function to generate qiniu file key.
  • upload_bucket, bucket_name, if not given, will use settings.QINIU_BUCKET_DEFAULT as default.
  • domain, your customized qiniu static domain, will use ('%s.qiniudn.com' % upload_bucket) as default if not given.

QiniuImageField is a subclass of QiniuFileField and designed to store especially image files.

2. Save your uploaded file in views.py

Save your uploaded file to qiniu server is very simple:

f = request.FILES['file']
obj = Photo()
obj.qiniu_file = f
# Calling save method will upload this file to qiniu server and requires network
# connection
obj.save()

How to use saved qiniu instance?

QiniuFileField

You can get the file url by: instance.qiniu_file.url

QiniuImageField

For QiniuImageField, There is a convient method called get_image_view which is used to get thumbnails of your images, such as:

instance.qiniu_image.get_image_view(mode=1, width=280, height=280, quality=75)
instance.qiniu_image.get_image_view(mode=2, width=640, quality=75)

For more information, visit(http://docs.qiniu.com/api/v6/image-process.html)

django-qiniu's People

Contributors

piglei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

django-qiniu's Issues

使用问题

image

在使用 QiNiuImageField 出现这样正常么?

def qiniu_key_maker_image(instance, filename):
    pass

还有这里怎么写呢

版本支持

这个仓库代码目前是不是不支持最新的SDK

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.