将javascript添加到django管理站点

时间:2014-11-24 11:23:15

标签: django checkbox django-admin sum

我按照以下步骤操作:

  1. settings.py
  2. STATIC_URL = '/static/'
    MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
    MEDIA_URL = '/media/'
    
    1. urls.py
    2.   

      ... + static(settings.MEDIA_URL,document_root = settings.MEDIA_ROOT)

      1. 将demo.js保存在myapp / static / myapp / js / demo.js
      2. $(document).ready(function() {
            $("h1").css("background-color","red");
        });
        
        1. admin.py
        2. class BaseAdmin(admin.ModelAdmin):
              class Media:
                  js = ['myapp/js/demo.js']
          admin.site.register(MyModel, BaseAdmin)
          

          当我打开管理网站时,没有任何改变。哪一步错了? 附:运行开发服务器" runserver"

1 个答案:

答案 0 :(得分:0)

尝试以下几点:

  1. MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

  2. (function ($) { $(document).ready(function ($) { $("h1").css("background-color","red"); }); })(django.jQuery);