Django-Filer: How to invoke upload widget outside admin

拜拜、爱过 提交于 2019-12-10 13:15:23

问题


How do I invoke the upload widget outside Admin? Using the standard form below does not work. The widget is corrupted.

forms.py
class PhotoAdd(forms.ModelForm):
    class Meta:
        model = Photo
        fields = ('ImageFilerField',)


views.py
def photoadd(request):
  context={}
  context['form'] = PhotoAdd()
  render(request, 'template.html', context)


template.html
{{ form }}

There is absolutely no reference to this in the documentation. How can I upload photos outside admin?

Edit: (added generated code from django above)

<label for="id_doc_pic">Doc pic:</label>
</th>
 <td>
   <span class="filerFile">
   <img id="id_doc_pic_thumbnail_img" src="/static/filer/icons/nofile_48x48.png" class="quiet" alt="no file selected" />
   &nbsp;<span id="id_doc_pic_description_txt"></span>
   <a href="/admin/filer/folder/last/?_to_field=file_ptr" class="related-lookup" id="lookup_id_doc_pic" title="Lookup">
   <img src="/static/admin/img/icon_searchbox.png" width="16" height="16" alt="Lookup" /></a><img id="id_doc_pic_clear" class="filerClearer" src="/static/admin/img/icon_deletelink.gif" width="10" height="10" alt="Clear" title="Clear" style="display: none;" /><br />
   <input class="vForeignKeyRawIdAdminField" id="id_doc_pic" name="doc_pic" type="text" />

<script type="text/javascript" id="id_doc_pic_javascript">
    django.jQuery(document).ready(function(){
        var plus = django.jQuery("#add_id_doc_pic");
        if (plus.length){
            plus.remove();
        }

        django.jQuery('#id_doc_pic_javascript').remove();
    });
</script>
</span>

Javascript Error: "Uncaught ReferenceError: django is not defined"

Could it be that I need to know what css to include and what javascript files to load?


回答1:


First of all, add {{ form.media }} in your html file, just after the tag <form> and {% csrf_token %}. Then extend the media class in your ModelForm of forms.py as explained by SteinRobert on Github issue: https://github.com/divio/django-cms/issues/6028. It works perfect! Thanks Stein!



来源:https://stackoverflow.com/questions/34141895/django-filer-how-to-invoke-upload-widget-outside-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!