Django Widget Media无效 [英] Django Widget Media doesn't work

查看:136
本文介绍了Django Widget Media无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个小部件,它只能显示一个块,因为我将使用jQuery添加功能。我试图通过媒体类的Widget包含JavaScript和样式表,它对我来说不起作用。

I need a widget, which should only display a block, because i will add functionality with jQuery. I am trying to include the javascript and stylesheet trough the "Media" class of Widget and it doesn't work for me.

这是代码:

class StarsWidget(Widget):
    """
    Widget with stars for rating
    """
    class Media:
        js = (
                settings.MEDIA_URL + 'js/rating.js',
              )

        css = {
                'screen': (
                    settings.MEDIA_URL + 'css/rating.css',
                    )
              }


    def render(self, name, value, attrs=None):
        if value is None: value = ''

        attrs = {'id':'ratingX', 'class':'rating'}
        final_attrs = self.build_attrs(attrs, name=name)
        if value != '':
            # Only add the 'value' attribute if a value is non-empty.
            final_attrs['value'] = force_unicode(value)
        return mark_safe(u'<div %s ></div>' % flatatt(final_attrs))

任何建议或帮助将不胜感激

Any suggestions or help will be appreciated

推荐答案

您是否真的在您的模板中包含表单媒体?

Are you actually including the form media in your template anywhere?

{% block extrahead %}
  {{ form.media }}
{% endblock %}

这篇关于Django Widget Media无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆