Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
django-ajax-upload-widget
Advanced tools
Provides AJAX file upload functionality for FileFields and ImageFields with a simple widget replacement in the form.
Provides AJAX file upload functionality for FileFields and ImageFields with a simple widget replacement in the form.
No change is required your model fields or app logic. This plugin acts transparently so your model forms can treat files as if they were uploaded by "traditional" browser file upload.
ClearableFileInput
widget (no change required to your model).Refer to the example
app included in the package for a working example.
Server Side '''''''''''
In your form, use the AjaxClearableFileInput
on your FileField
or ImageField
.
::
from django import forms
from ajax_upload.widgets import AjaxClearableFileInput
class MyForm(forms.Form):
my_image_field = forms.ImageField(widget=AjaxClearableFileInput())
Or, if using a ModelForm
you can just override the widget.
::
from django import forms
from ajax_upload.widgets import AjaxClearableFileInput
class MyForm(forms.ModelForm):
class Meta:
model = MyModel
widgets = {
'my_image_field': AjaxClearableFileInput
}
Client Side '''''''''''
Include the Javascript (and optionally CSS) files in your page and call the autoDiscover
function.
This will search the page for all the AJAX file input fields and apply the necessary Javascript.
::
<link href="{{ STATIC_URL }}ajax_upload/css/ajax-upload-widget.css" rel="stylesheet" type="text/css"/>
<script src="{{ STATIC_URL }}ajax_upload/js/jquery.iframe-transport.js"></script>
<script src="{{ STATIC_URL }}ajax_upload/js/ajax-upload-widget.js"></script>
<script>
$(function() {
AjaxUploadWidget.autoDiscover();
});
</script>
You can also pass options to autoDiscover()
:
::
<script>
$(function() {
AjaxUploadWidget.autoDiscover({
changeButtonText: 'Click to change',
onError: function(data) { alert('Error!'); }
// see source for full list of options
});
});
</script>
OR ... you can explicitly instantiate an AjaxUploadWidget on an AJAX file input field: ::
<input id="Foo" name="foo" type="file" data-upload-url="/ajax-upload/" data-filename="" data-required=""/>
<!-- The input field needs to be outputed by Django to contain the appropriate data attributes -->
<script>
new AjaxUploadWidget($('#Foo'), {
// options
});
</script>
Add ajax_upload
to your INSTALLED_APPS
setting.
Hook in the urls. ::
urlpatterns += patterns('', (r'^ajax-upload/', include('ajax_upload.urls')), )
That's it (don't forget include the Javascript as mentioned above).
::
./manage.py test ajax_upload
This app is licensed under the BSD license. See the LICENSE file for details.
FAQs
Provides AJAX file upload functionality for FileFields and ImageFields with a simple widget replacement in the form.
We found that django-ajax-upload-widget demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.