使用Django 1.8,Python 3.4和Bootstrap 3,表格呈现但缺少网格/ css。(见下图)。
我已经按docs安装了django-tables2我也运行了collecstatic(localhost)它也出现在我的virtualenv django1834 / static / django_tables2 / themes / paleblue / css
非常感谢任何帮助/建议
#settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.core.context_processors.request',
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
...
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
#views.py
from django_tables2 import RequestConfig
from cdpapp.tables import WorkOrderTable
...
def list_all_workorders(request):
table = WorkOrderTable(WorkOrder.objects.all())
RequestConfig(request).configure(table)
return render(request, 'cdpapp/workorder_all_list.html', {'table': table})
#tables.py
import django_tables2 as tables
from django_tables2.utils import A # alias for Accessor
from cdpapp.models import WorkOrder
class WorkOrderTable(tables.Table):
class Meta:
model = WorkOrder
fields = ("call_date", "ordernum", "building", "unit", "request_by", 'problem_desc')
attrs = {"class": "paleblue"}
#template
{% extends "cdpapp/base_no_side_panel.html" %}
{% load render_table from django_tables2 %}
{% load staticfiles %}
{% block title %}All Work Orders{% endblock %}
<head>
<link rel="stylesheet" href="{{ STATIC_URL }}django_tables2/themes/paleblue/css/screen.css" />
</head>
{% block content %}
{% render_table table %}
{% endblock content %}
答案 0 :(得分:0)
看来问题是你如何定义attrs
。 attrs
应该是Meta
类中Table
类的元素。您需要再缩进attrs
一级。
class WorkOrderTable(tables.Table):
class Meta:
model = WorkOrder
fields = ("call_date", "ordernum", "building", "unit",
"request_by", 'problem_desc')
attrs = {"class": "paleblue"}
另外,请你澄清一下你的问题吗?
你说它缺少'grid / css'。这是否意味着您希望桌子显示边框?
在运行测试服务器时,您可以通过网址http://127.0.0.1:8000/static/django_tables2/themes/paleblue/css/screen.css检索screen.css
文件。如果css文件没有加载,那么您可能设置了一些错误的设置。