Appropriate way to handle deprecated `adminmedia` templatetag and {% admin_media_prefix %}

删除回忆录丶 提交于 2019-12-02 22:12:53
Anton Morozov

Since Django 1.3 you can use django.contrib.staticfiles app.

Make sure that django.contrib.staticfiles is included in your INSTALLED_APPS and the STATIC_ROOT and STATIC_URL options are specified in your settings.py.

Then run manage.py collectstatic command and all applications' static files will be collected in STATIC_ROOT folder.

In the templates you can use the {{ STATIC_URL }} context variable (make sure that django.core.context_processors.static is included in TEMPLATE_CONTEXT_PROCESSORS) or the {% static %} template tag.

<link href="{{ STATIC_URL }}admin/css/login.css" rel="stylesheet">

or

{% load staticfiles %}
<link href="{% static 'admin/css/login.css' %}" rel="stylesheet">

I just copied what's in base.css:

{% load admin_static %}

and then

<link href="{% static 'admin/css/base.css' %}" rel="stylesheet">

(replace base.css with whatever you need, like login.css in your case)

Make sure you have django.contrib.staticfiles in your INSTALLED_APPS.

(I didn't need to configure STATIC_ROOT and run manage.py collectstatic as suggested previously by Anton)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!