Django Widget Media doesn't work

后端 未结 3 1626
走了就别回头了
走了就别回头了 2020-12-17 20:36

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\"

相关标签:
3条回答
  • 2020-12-17 20:54

    Minor optimization: You don't need to prepend settings.MEDIA_URL to your paths, it's done automatically when it's printed out.

    0 讨论(0)
  • 2020-12-17 20:55

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

    {% block extrahead %}
      {{ form.media }}
    {% endblock %}
    
    0 讨论(0)
  • 2020-12-17 21:05

    Paths in "class Media" are automatically prepended with settings.MEDIA_URL. So try like this:

    class Media:
        js = ('js/rating.js',)
        css = {'screen': ('css/rating.css',),}
    

    If it will not work, I suggest using FireBug or something like it and checking if browser is able to load css and javascript.

    Based on comment: It appears, that you are not loading your form media at all. Try adding in the template:

    {{ my_form.media }}
    

    in {% block subheader %} (or wherever you are loading scripts and css), where "my_form" is the name of your form instance, created in the view.

    0 讨论(0)
提交回复
热议问题