django-ajaximage
Ajax image uploads.
Upload images via ajax. Images are optionally resized.
Optimized on https://github.com/bradleyg/django-ajaximage.
Features Appended:
- Correctly display the readonly field
- Support django2 and above
upload_tosupport datetime string format- Change FileField to ImageFileField to compatible with ImageField
- Add format_image method to display custom image field using the same format
from ajaximage.utils import format_image class xxxAdmin(ModelAdmin): ... def some_field(obj): return format_image(obj.some_field.ajaximagefield)
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.
Metadata
Release files for django2-ajaximage 0.9.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django2-ajaximage-0.9.0.tar.gz | 9.7 kB | Without provenance | Details for django2-ajaximage-0.9.0.tar.gz |
Release files / django2-ajaximage-0.9.0.tar.gz
| Download URL | django2-ajaximage-0.9.0.tar.gz |
|---|---|
| Size | 9.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2854814dd6f3c915743ebbe5e2d4b59bb18eee409bc485bfd80e783e9e721f8f
|
|
BLAKE2b-256 checksum How to use checksums |
93d839facf5d66b34a459ae954edc4be7f58456885d3588b43b166c4278bc9df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9
|
Security for django2-ajaximage 0.9.0
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.