0

I have installed django-admin-tools and created a dashboard.py in my project folder.

Inside this file I have specified a media class:

#myproject/dashboard.py 
class Media: 
        css = ('',) 
        js = ('http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/ 
jquery.min.js',) 

In my settings I have:

#settings.py
# admin_tools 
ADMIN_TOOLS_INDEX_DASHBOARD = 
'myproject.dashboard.CustomIndexDashboard' 
ADMIN_TOOLS_APP_INDEX_DASHBOARD = 
'myproject.dashboard.CustomAppIndexDashboard' 

And my URLs are configured as follows:

#urls.py
... 
urlpatterns+= patterns('', 
        url(r'^admin_tools/', include('admin_tools.urls')), 
        url(r'^admin/', admin.site.urls), 

        url(r'', include('feincms.urls')), 

) 

Anyone see any glaring mistakes? I don't see the jquery file being downloaded in firebug. I assume jquery is also part of admin_tools, but this error message seems to indicate it is not?

Uncaught TypeError: Property '$' of object [object DOMWindow] is not a 
function 

Any help is appreciated.

4

2 回答 2

1

我认为这可能是因为 jQuery 函数已在 django admin 中重命名以避免冲突。
如果您可以看到 jquery 文件正在视图源中加载,并且在控制台中键入 $ 会产生该错误,那么请尝试 django.jQuery
如果您想使用 $,您需要执行 $ = django.jQuery 之类的操作,然后在脚本的底部,将其放回 django.jQuery
参见https://github.com/philippbosch/django-geoposition/blob/master/geoposition/static/geoposition/geoposition.js例如。

于 2013-01-28T15:06:42.613 回答
0

你是对的,jquery 已经包含在 admin_tools 中。除非您需要更新的版本,否则最好使用随附的版本。或者即使没有 Media 类它也不会加载?

您的设置中存在问题的是您从外部主机加载 jquery。我也希望这可以工作,但是,如果您查看 admin_tools 中注入文件的dashboard.html 模板,您会注意到它预先{{ media_url }}添加到每个 js 文件中。结果是无效的包含 like '/media/http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'。这显然是 admin_tools 的问题,我会提交错误报告。

作为一种解决方法,您可以删除 Media 类并覆盖 dashboard.html 以包含您的外部文件。

于 2012-03-12T21:59:10.113 回答