Skip to content

Upload images via ajax. Images are optionally resized.

License

Notifications You must be signed in to change notification settings

jmp0xf/django-ajaximage

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-ajaximage

Ajax image uploads.

PyPi Version PyPi Downloads

Upload images via ajax. Images are optionally resized.

screenshot

Support

Python 2/3 Chrome / Safari / Firefox / IE10+

For older browser support use version 0.1.18.

Installation

Install with Pip:

pip install django-ajaximage

Django Setup

settings.py

INSTALLED_APPS = [
    ...
    'ajaximage',
    ...
]

# Settings
AJAXIMAGE_AUTH_TEST = lambda u: True

urls.py

urlpatterns = patterns('',
    url(r'^ajaximage/', include('ajaximage.urls')),
)

Run python manage.py collectstatic if required.

Use in Django admin only

models.py

from django.db import models
from ajaximage.fields import AjaxImageField

class Example(models.Model):
    thumbnail = AjaxImageField(upload_to='thumbnails',
                               max_height=200, #optional
                               max_width=200, # optional
                               crop=True) # optional

# if crop is provided both max_height and max_width are required

Use the widget in a custom form

forms.py

from django import forms
from ajaximage.widgets import AjaxImageWidget

class AjaxImageUploadForm(forms.Form):
    images = forms.URLField(widget=AjaxImageWidget(upload_to='form-uploads'))

views.py

from django.views.generic import FormView
from .forms import AjaxImageUploadForm

class MyView(FormView):
    template_name = 'form.html'
    form_class = AjaxImageUploadForm

templates/form.html

<html>
<head>
    <meta charset="utf-8">
    <title>ajaximage</title>
    {{ form.media }}
</head>
<body>
    {{ form.as_p }}
</body>
</html>

Examples

Examples of both approaches can be found in the examples folder. To run them:

$ git clone [email protected]:bradleyg/django-ajaximage.git
$ cd django-ajaximage
$ python setup.py install
$ cd example

$ python manage.py syncdb
$ python manage.py runserver 0.0.0.0:5000

Visit http://localhost:5000/admin to view the admin widget and http://localhost:5000/form to view the custom form widget.

About

Upload images via ajax. Images are optionally resized.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 70.4%
  • JavaScript 25.8%
  • CSS 3.0%
  • HTML 0.8%