How I can access to the jQuery, it is build-in Django-Admin, in my custom views?

1,736 views
Skip to first unread message

Seti Volkylany

unread,
Jul 3, 2016, 11:36:18 AM7/3/16
to Django users


The Django`s docs tell next:
To avoid conflicts with user-supplied scripts or libraries, Django’s jQuery (version 2.1.4) is namespaced as django.jQuery. If you want to use jQuery in your own admin JavaScript without including a second copy, you can use the django.jQuery object on changelist and add/edit views.
(see https://docs.djangoproject.com/es/1.9/ref/contrib/admin/…)

But, how using this build-in jQuery. When I am tring to use $ in my custom view I had:

$('body')
Uncaught TypeError: $ is not a function(…)

But it is successfully worked in main page of the Django-Admin

$('body')
<body class="dashboard" cz-shortcut-listen="true">…</body>

Luis Zárate

unread,
Jul 3, 2016, 2:08:48 PM7/3/16
to django...@googlegroups.com
Replace $ by django.jQuery

For example django.jQuery('body')
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3c5ab528-05fa-4446-88c3-c2a2419d24fe%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

--
"La utopía sirve para caminar" Fernando Birri



Seti Volkylany

unread,
Jul 3, 2016, 2:20:34 PM7/3/16
to django...@googlegroups.com
It is not worked even the main admin page

django.jQuery('body')
Uncaught ReferenceError: django is not defined(…)(anonymous function) @ VM9451:1
$()
null
$django.jQuery('body')
Uncaught ReferenceError: $django is not defined(…)


--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/h4QKC2xHY60/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Luis Zárate

unread,
Jul 5, 2016, 1:26:16 AM7/5/16
to django...@googlegroups.com
Are you using django admin template?
Where are your Jquery call? in the header ?

A template example could be useful.


For more options, visit https://groups.google.com/d/optout.

Seti Volkylany

unread,
Jul 5, 2016, 9:44:23 AM7/5/16
to django...@googlegroups.com
I resolved my problem added two scripts to template 

<script src="{% static 'admin/js/vendor/jquery/jquery.min.js' %} " type="text/javascript" charset="utf-8"></script>
<script src="{% static 'admin/js/jquery.init.js' %} " type="text/javascript" charset="utf-8"></script>

but thank you for responsive

Reply all
Reply to author
Forward
0 new messages