Forums

jQuery method/function missing when using provided jQuery in Django admin?

I was following Django tutorials part 2 (for version 1.5) https://docs.djangoproject.com/en/1.5/intro/tutorial02/#adding-related-objects and I don't see "Add another Choice" button in my admin page. I opened Firebug (also tested on Chrome, just in case) and see "TypeError: $(...).tabularFormset is not a function" in Console. It seems like Django is not recognizing jQuery variable somehow? If anyone knows an answer to this, please let me know. I tried Googleing around, but there seems to be no similar issue reported. Thank you.

Do you have a live site showing the problem I could look at? Send me a private message via the "Send feedback" link above if you don't want to give a link publicly.

For anyone else that runs into this: the problem will happen if you start with our Django quickstart and then switch to using a virtualenv.

When you use our normal Django quickstart, we add the Django 1.3 admin static files by default to your web app (from /usr/local/lib/python2.7/site-packages/django/contrib/admin/media). You'll see the static file mapping listed on the Web tab.

But you actually want the Django 1.5 static files from your virtualenv.

The simplest way is probably to set up a STATIC_ROOT in your settings.py, and use the collectstatic command to gather all the static files into it. That will copy all the admin js and css from your virtualenv into the folder you set up in STATIC_ROOT. The final link in the chain is to make sure you have a static files mapping set up on the web tab which maps to STATIC_ROOT. If you want to use the {% static syntax, make sure it also matches STATIC_URL

Then, delete the /static/admin/ mapping, and set one up that maps instead...

More info:

https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#django-admin-collectstatic

To add to @harry's solution, @giles also gave me an alternative solution, which I tested and works. When I ran into this problem, I had my webapp static file mapping as:

URL Directory /static/admin/ /usr/local/lib/python2.7/site-packages/django/contrib/admin/media

I changed it to:

URL Directory /static/admin/ /home/{my_home}/.virtualenvs/{virtual_env_name}/lib/python2.7/site-packages/django/contrib/admin/static/admin

Please note that I have installed Django 1.5 in my {virtual_env_name}.