我复制了 django_tables2 网站示例中显示的具有 paleblue 类的 screen.css。
我将它放在我的应用程序中的 static/css 文件夹中,当我从我的 .html 调用它时,它会找到它。在标题中,我放置了以下内容:
<link rel="stylesheet" href="{{ STATIC_URL }}css/screen.css" />
现在,在我的 tables.py 模块中我有这个:
import django_tables2 as tables
class TipPredmetaTable(tables.Table):
class Meta:
model = models.TipPredmeta
attrs = {'class': 'paleblue'}
在我的 views.py 中我有这个:
def tippredmeta(request):
queryset = TipPredmeta.objects.all()
table = TipPredmetaTable(queryset)
RequestConfig(request).configure(table)
return render_to_response('azuriranje/tabela.html', {"table": table}, context_instance=RequestContext(request))
当我在 Mozzila 中打开页面并按下 Ctrl+U 时,我可以清楚地看到以下内容:
<div class="table-container"><table class="paleblue"><thead> <tr>...
我的 .html 与 django_tables2 网站上的完全一样,我的 STATIC_URL 已定义,staticfiles 应用程序已启用。我做错了什么?
最佳答案
好的,在通过网络和我的代码进行更广泛的搜索后,我已经弄明白了。看来我忘记将 'django.core.context_processors.static'
放入 TEMPLATE_CONTEXT_PROCESSOR
是我问题的根源。
关于python - Django_tables2 : CSS isn't working even though it's registered,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20019166/