1

I've got a Django form that is displaying a ClearableFileInput for a CloudinaryImage (from Cloudinary). Things are working great, except when I display the form field, I get a mangled href in the anchor element:

Currently: <a href="&lt;bound method CloudinaryImage.url of &lt;cloudinary.CloudinaryImage object at 0x10b3f4ad0&gt;&gt;">&lt;cloudinary.CloudinaryImage object at 0x10b3f4ad0&gt;</a> <input type="checkbox" name="logo-clear" id="logo-clear_id" /> <label for="logo-clear_id">Clear</label><br />Change: <input id="id_logo" type="file" name="logo" class="span4" />

Here is the template code I am using:

<div class="fieldWrapper">
    <label for="id_logo"><h3>{{ form.logo.label }}:</h3></label>
    {{ form.logo|add_class:"span4" }}
    <p>{{ form.logo.help_text }}</p>
</div>

The add_class part come from django-widget-tweaks. I've taken the add_class part out with no change in the output.

Here is my form definition:

class OrganizationFormTheme(forms.ModelForm):
    pass

    class Meta:
        fields = ('logo',)
        model = Organization

It looks like Django is having problems with the CloudinaryImage's url function. I suspect it is looking for a simple property rather than a function.

Any suggestions on how to handle this? Should I subclass CloudinaryImage and rewrite the url function somehow?

Erik
  • 7,479
  • 8
  • 62
  • 99
  • Can you show your Form definition? – jcater Sep 11 '12 at 03:43
  • I decided to just build the form widget manually in my template. Would be nice if I didn't have to though. – Erik Sep 11 '12 at 07:02
  • I had a similar error. You are referencing the method, not its output. – K-man Sep 11 '12 at 22:05
  • Exactly -- only it is Django's template code {{ form.logo }} that is referencing the method, not its output. Is there a way to change this? – Erik Sep 11 '12 at 22:20

1 Answers1

0

Indeed there was a conflict between the url function and the url property. We've changed the function to be build_url instead of url.

In addition, you can specify transformation parameters as the url_options parameter when calling the constructor of CloudinaryImage. Then you can use the url property for getting the full Cloudinary URL.

The fix is available in the latest release of the Python library: http://pypi.python.org/pypi/cloudinary

Cloudinary
  • 541
  • 3
  • 4
  • I've changed my implementation so I can't check this solution -- but it sounds like you made a change that fixed the situtation. Thanks for the attention and great service. – Erik Oct 28 '12 at 17:39