5

i an doing exactly the same Django admin datepicker calendar and clock img and i am suffering with the same problem but it was working perfectly fine with django 1.4 but when i updated it to django 1.5 it is giving me this error

'adminmedia' is not a valid tag library: Template library adminmedia not found, tried django.templatetags.adminmedia,django.contrib.staticfiles.templatetags.adminmedia,django.contrib.admin.templatetags.adminmedia,django.contrib.humanize.templatetags.adminmedia,jobpost.templatetags.adminmedia,crispy_forms.templatetags.adminmedia,tinymce.templatetags.adminmedia,haystack.templatetags.adminmedia

here is my code:

{% load adminmedia %}


{% load i18n %}
{% load crispy_forms_tags %} 
{% block content %}

<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="/my_admin/jsi18n/"></script>
<script type="text/javascript" src="/media/admin/js/core.js"></script>
{{ form.media }}
<link rel="stylesheet" type="text/css" href="/static/admin/css/forms.css"/>
<link rel="stylesheet" type="text/css" href="/static/admin/css/base.css"/>
<link rel="stylesheet" type="text/css" href="/static/admin/css/global.css"/>
<link rel="stylesheet" type="text/css" href="/static/admin/css/widgets.css"/>

<script type="text/javascript" src="/admin/jsi18n/"></script>
<script type="text/javascript" src="/static/admin/js/core.js"></script>
<script type="text/javascript" src="/static/admin/js/admin/RelatedObjectLookups.js">      </script>
<script type="text/javascript" src="/static/admin/js/jquery.js"></script>
<script type="text/javascript" src="/static/admin/js/jquery.init.js"></script>
<script type="text/javascript" src="/static/admin/js/actions.js"></script>
<script type="text/javascript" src="/static/admin/js/calendar.js"></script>
<script type="text/javascript" src="/static/admin/js/admin/DateTimeShortcuts.js"> </script>
<script type="text/javascript">
window.__admin_media_prefix__ = "{% filter escapejs %}{% admin_media_prefix %}{%    endfilter %}";
</script>
<script type = “text/javascript” src=”../jscripts/tiny_mce/tiny_mce.js”></script> 

<script>

by doing this i am showing image of calender widget from /static/admin/img/icon_calender.jpg. but admin media option is deprecated in django version 1.5 or later so then i replace this with static media option and here is the new code:

{% load staticfiles %}

{% load i18n %}
{% load crispy_forms_tags %} 
{% block content %}

<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="/my_admin/jsi18n/"></script>
<script type="text/javascript" src="/media/admin/js/core.js"></script>
{{ form.media }}
<link rel="stylesheet" type="text/css" href="/static/admin/css/forms.css"/>
<link rel="stylesheet" type="text/css" href="/static/admin/css/base.css"/>
<link rel="stylesheet" type="text/css" href="/static/admin/css/global.css"/>
<link rel="stylesheet" type="text/css" href="/static/admin/css/widgets.css"/>
<link href="{% static 'admin/css/login.css' %}" rel="stylesheet">

and it look like this:

enter image description here

my calender icon is gone. can anyone tell me whats the alternative of this problem in version 1.5

help will be appreciated

Community
  • 1
  • 1
numerah
  • 498
  • 7
  • 29
  • 1
    The location of Django admin static media has moved from `django/contrib/admin/media/` to `django/contrib/admin/static/admin/`. You need to remove the `{% adminmedia %}`. tag. Now, the /admin` is just an subdirectory of `/static/` – karthikr Jun 26 '13 at 12:14
  • then what should we do. kindly provide proper answer so i can accept. – numerah Jun 26 '13 at 12:18
  • Try `ADMIN_MEDIA_PREFIX='/static/'` – karthikr Jun 26 '13 at 12:19
  • I would do 2 things: 1. add `django.contrib.staticfiles` to `INSTALLED_APPS` and then set `STATIC_URL` to `/static/` - was wrong about `ADMIN_MEDIA_PREFIX` – karthikr Jun 26 '13 at 14:39
  • its already done. my settings file have all of these info. – numerah Jun 27 '13 at 05:24

3 Answers3

1

The response is right here, in the 1.5 release notes: https://docs.djangoproject.com/en/dev/releases/1.5-beta-1/#miscellaneous

The {% admin_media_prefix %} became deprecated, you must remove it from your templates. (Included every {% load adminmedia %}, which causes the exception). There must be a setting which replace this tag I guess.

Maxime Lorant
  • 34,607
  • 19
  • 87
  • 97
  • yes i know the deprecated problem . thats why i am searching for alternatives . kindly tell me if u know any. – numerah Jun 26 '13 at 11:54
  • 1
    Yeah, I remember now. Every admin media are available through the `static` tag since the 1.3. You just have to replace `{% admin_media_prefix %}/your/file.css` by `{% static "admin/your/file.css" %}`. More information also here: http://stackoverflow.com/a/13627047/1433392 :) – Maxime Lorant Jun 26 '13 at 11:56
  • I'm still seeing a `{% load adminmedia %}` (line 1) and `{% admin_media_prefix %}` (4 lines before end)... – Maxime Lorant Jun 26 '13 at 12:04
1

so django 1.5 was giving me nightmare so i resolved my problem by using direct jquery datpicker here is the jquery datepicker

all i had to do is change the id which is a little bit tricky in django .for example if your date field name is start_date then id will be formtools_start_date . and for this kind of datepicker you don't even need any icon to show.. this helped me i hope this will help those also whoever upgraded their django version.

numerah
  • 498
  • 7
  • 29
1

I just had this problem today - not being able to load admin base.css. I upgraded Django for my site from v1.2 to v1.5 and encountered the issue. I found that the href is /static/admin/css/base.css and could not find out how to change it. So I did these:

  1. Copied site-packages/django/contrib/admin/static/admin/* to my Django project's static directory so it would be like
   top/
      static/
         admin/
            css/
            js
            images
  1. Editted urls.py, added the following line in the urlpatterns = patterns('',...

    (r'^static/(?P.*)$','django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes':True}),

That's it. It worked.

yoshi
  • 1,070
  • 9
  • 16