问题
I'm using the admin datepicker in my form, but it is not displaying the clock and calendar images.
Here's the head of my template:
{% extends "shared/base.html" %}
{% load adminmedia %}
{% block extra_head %}
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}admin/css/forms.css"/>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}admin/css/base.css"/>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}admin/css/global.css"/>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}admin/css/widgets.css"/>
<script type="text/javascript" src="/admin/jsi18n/"></script>
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/core.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/admin/RelatedObjectLookups.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/jquery.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/jquery.init.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/actions.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/calendar.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/admin/DateTimeShortcuts.js"></script>
{% endblock %}
With this I get:
"GET /missing-admin-media-prefix/img/icon_clock.gif HTTP/1.1" 404 4049
"GET /missing-admin-media-prefix/img/icon_calendar.gif HTTP/1.1" 404 4058
So I added
<script type="text/javascript">window.__admin_media_prefix__ = "{% filter escapejs %}{%admin_media_prefix %}{% endfilter %}";</script>
to the head and now I get:
"GET /media/admin/img/icon_calendar.gif HTTP/1.1" 404 4013
"GET /media/admin/img/icon_clock.gif HTTP/1.1" 404 4004
Any idea what I'm doing wrong? Do I need to change something in my settings.py?
回答1:
i was suffering with the same problem.All you need to do is add "ADMIN_MEDIA_PREFIX" in you settings.py file
just write
ADMIN_MEDIA_PREFIX = '/static/admin/'
if you have static directory in your project. name it according to your directory name. if its already named as static then use the above.
来源:https://stackoverflow.com/questions/15357978/django-admin-datepicker-calendar-and-clock-img