Upload images via ajax. Images are optionally resized.
Project description
django-ajaximage
Ajax image uploads.
Upload images via ajax. Images are optionally resized.
Support
Python 3 Django > 2.0 Chrome / Safari / Firefox / IE10+
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 += [
path('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 git@github.com:bradleyg/django-ajaximage.git
$ cd django-ajaximage
$ python setup.py install
$ cd example
$ python manage.py migrate
$ python manage.py createsuperuser
$ python manage.py runserver
Visit http://localhost:8000/admin to view the admin widget and http://localhost:8000/form to view the custom form widget.
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
django2-ajaximage-0.4.0.tar.gz
(10.3 kB
view details)
File details
Details for the file django2-ajaximage-0.4.0.tar.gz.
File metadata
- Download URL: django2-ajaximage-0.4.0.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6a86ff6c60b80b1eace7efc7fde595a361ea51ae27c573d58d9fa10cc24e293
|
|
| MD5 |
1208917c5a262d1608e5eb8b67c80016
|
|
| BLAKE2b-256 |
73f5030b3cadb9e6c907a82ac3d863b7bd90822f291a44111c1f3b3d97983c16
|