Getting the Django admin media
The Django Admin module includes several of its own JavaScript files on several pages. I would like to include these media files for a custom view. How can I do this?
I've looked through the admin templates but I'm开发者_Go百科 not sure what the best way to do this is.
Update: Or, I could just go to a page and copy/paste the scripts. Although it feels like there's a better way to do it.
In settings.py you need enable context processors - TEMPLATE_CONTEXT_PROCESSORS
("django.contrib.auth.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", "django.core.context_processors.static", "django.contrib.messages.context_processors.messages")
can read more here http://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-context-requestcontext If you are using render_to_response function, you can return something like this
return render_to_response('template.html', {}, RequestContext(request))
after this you can use media option in your templates like {{ ADMIN_MEDIA_PREFIX }}js/name_of_file.js
精彩评论