Posts Tagged “django

Integrating Uploadify with Django

29-07-2011 Alec Hussey 5 Comments

As multimedia becomes more and more prevalent these days, an interactive file uploader becomes extraordinarily useful. I ran into such a situation recently when developing a Django web application of my own. In this case I chose to use Uploadify because I’ve used it in the past, it integrates well with jQuery, and in my experience has been not only the easiest to work with but the least problematic.

Working with flash-based file upload systems is relatively easy with Django assuming that they send a standard POST request to the server and you understand the way Django chooses to handle file uploads. Django provides file upload handlers which may be modified to perform more sophisticated tasks during file uploads if you wish, but in this case we will stick with the built in upload handlers. When you upload a file to a Django view it takes the name of the upload field in your template and puts that name into the request.FILES dictionary where the value of that entry is an UploadedFile object or a subclass thereof. This UploadedFile object contains basic information about the file being uploaded including its file name as it was uploaded and its complete size. In addition, it gives you file-like access methods to the uploaded data which allow you, the programmer, to decide how the data gets stored.

(more…)

Filed under:
Tags: , , , , , ,

Integrating TinyMCE with Django

09-12-2009 Alec Hussey 9 Comments

Many people often want What You See Is What You Get (WYSIWYG) editors when creating content from within their web applications. This can be either in the Django admin control panel or for the end user. One of the most flexible and useful of the WYSIWYG editors currently available is TinyMCE due to its extensive plugin library and robust feature set. Integration with Django is relatively simple given that you extend the functionality of built in classes.

The first thing we will need to do is create a custom widget from forms.Textarea found in the django.forms module. We accomplish this by inheriting the Textarea class and overriding the constructor and render methods. Defining the relative path (on your web server) to the TInyMCE javascript source is also required here. So be aware that you will need to change that path to suite your environment. You may also want to change the content_css variable to include your sites’ main CSS file. The following is the source code for widgets.py which should be place in your projects root directory.

(more…)

Filed under:
Tags: , , , ,