django-filepicker

pypi-release pypi-downloads

A django plugin to make integrating with Filepicker.io even easier

##Installation

  1. Install the python package:

    pip install django-filepicker
    
  2. Add your file picker api key to your settings.py file. You api key can be found in the developer portal.

    FILEPICKER_API_KEY = <your api key>
    
  3. Configure your media root.

    CWD = os.getcwd()
    MEDIA_ROOT = os.path.join(CWD, 'media')
    
  4. Add a filepicker field to your model and set the upload_to value.

    # *Please note, that FPFileField handle only one file*
    # In demo you can see how to handle multiple files upload.
    fpfile = django_filepicker.models.FPFileField(upload_to='uploads')
    
  5. Modify your view to accept the uploaded files along with the post data.

    form = models.TestModelForm(request.POST, request.FILES)
    if form.is_valid():
        #Save will read the data and upload it to the location
        # defined in TestModel
        form.save()
    
  6. Add the form.media variable above your other JavaScript calls.

    <head>
        <title>Form Template Example</title>
        <!--  Normally this would go into a block defined in base.html that
              occurs before other JavaScript calls. -->
        {{ form.media }}
    </head>
    
    <body>
        <form method="POST" action="/" enctype="multipart/form-data">
            {{ form.as_p }}
            <input type="submit" />
        </form>
    </body>
    

##Demo To see how all the pieces come together, see the example code in demo/, which you can run with the standard python manage.py runserver command

###models.py import django_filepicker class TestModel(models.Model): #FPFileField is a field that will render as a filepicker dragdrop widget, but #When accessed will provide a File-like interface (so you can do fpfile.read(), for instance) fpfile = django_filepicker.models.FPFileField(upload_to='uploads')

###views.py #building the form - automagically turns the uploaded fpurl into a File object form = models.TestModelForm(request.POST, request.FILES) if form.is_valid(): #Save will read the data and upload it to the location defined in TestModel form.save()

Be sure to also provide your Filepicker.io api key, either as a parameter to the FPFileField or in settings.py as FILEPICKER_API_KEY

##Components ###Models The filepicker django library defines the FPFileField model field so you can get all the benefits of using Filepicker.io as a drop-in replacement for the standard django FileField. No need to change any of your view logic.

###Forms Similarly with the FPFileField for models, the filepicker django library defines a FPFileField for forms as well, that likewise serves as a drop-in replacement for the standard django FileField. There is also the FPUrlField if you want to store the Filepicker.io URL instead

###Middleware Also included is a middleware library that will take any Filepicker.io urls passed to the server, download the contents, and place the result in request.FILES. This way, you can keep your backend code for handling file uploads the same as before while adding all the front-end magic that Filepicker.io provides

If you have any questions, don't hesitate to reach out at contact@filepicker.io. For more information, see https://filepicker.io

Open-sourced under the MIT License. Pull requests encouraged!



django-filepicker

pypi-releasedata-canonical-src 的PyPI的下载data-canonical-src

一个django插件使得与Filepicker.io集成更加容易

##安装

  1. Install the python package:

    pip install django-filepicker
    
  2. Add your file picker api key to your settings.py file. You api key can be found in the developer portal.

    FILEPICKER_API_KEY = <your api key>
    
  3. Configure your media root.

    CWD = os.getcwd()
    MEDIA_ROOT = os.path.join(CWD, 'media')
    
  4. Add a filepicker field to your model and set the upload_to value.

    # Please note, that FPFileField handle only one file

    In demo you can see how to handle multiple files upload.

    fpfile = django_filepicker.models.FPFileField(upload_to='uploads')

  5. Modify your view to accept the uploaded files along with the post data.

    form = models.TestModelForm(request.POST, request.FILES)
    if form.is_valid():
        #Save will read the data and upload it to the location
        # defined in TestModel
        form.save()
    
  6. Add the form.media variable above your other JavaScript calls.

    <head>
        <title>Form Template Example</title>
        <!–  Normally this would go into a block defined in base.html that
              occurs before other JavaScript calls. –>
        {{ form.media }}
    </head>

    <body> <form method="POST" action="/" enctype="multipart/form-data"> {{ form.as_p }} <input type="submit" /> </form> </body>

演示 要了解所有的内容是如何组合的,请参阅demo /中的示例代码,您可以使用该标准运行 python manage.py runserver 命令

### models.py 导入django_filepicker TestModel类(models.Model): #FPFileField是一个将作为filepicker拖放小部件呈现的字段,但是 #当访问将提供一个类文件的界面(所以你可以做fpfile.read(),例如) fpfile = django_filepicker.models.FPFileField(upload_to =‘uploads’)

### views.py #building表单 - 将上传的fpurl自动转换为File对象 form = models.TestModelForm(request.POST,request.FILES) 如果form.is_valid(): #Save将读取数据并将其上传到TestModel中定义的位置 form.save()

确保还提供您的Filepicker.io api密钥,作为FPFileField的参数或settings.py中的 FILEPICKER_API_KEY

组件 ###楷模 filepicker django库定义了 FPFileField 模型字段,因此您可以获得使用Filepicker.io作为标准django FileField 的替代替代的所有好处。无需更改任何视图逻辑。

###表单 与模型的 FPFileField 类似,filepicker django库也为表单定义了一个 FPFileField ,同样也作为标准django FileField的替换。如果要存储Filepicker.io URL,也可以使用 FPUrlField

###中间件 还包括一个中间件库,它将把任何Filepicker.io URL传递给服务器,下载内容,并将结果放在request.FILES中。这样,您可以保留您的后端代码来处理与上述相同的文件上传,同时添加Filepicker.io提供的所有前端魔法

如果您有任何问题,请随时与 contact@filepicker.io 联系。有关详细信息,请参阅 https://filepicker.io

根据麻省理工学院许可证开源。鼓励请求!




相关问题推荐