2015-11-09 49 views
0

使用Django 1.8,Python 3.4和Bootstrap 3,表格呈現,但缺少grid/css(見下圖)。是否與django1.8和bootstrap3一起使用django-tables2?

我已經安裝Django的tables2每docs我也跑collecstatic(本地主機)它也出現在我的virtualenv django1834 /靜態/ django_tables2 /主題/ 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 %} 

enter image description here

回答

0

看來,問題是你如何定義attrsattrs應該是Table類中的Meta類的元素。你需要縮進attrs一個級別。

class WorkOrderTable(tables.Table): 
    class Meta: 
     model = WorkOrder 
     fields = ("call_date", "ordernum", "building", "unit", 
       "request_by", 'problem_desc') 
     attrs = {"class": "paleblue"} 

另外,請您澄清一下您的問題嗎?

你說它缺少'grid/css'。這是否意味着你希望你的桌子顯示邊框?

運行測試服務器時,您可以通過url http://127.0.0.1:8000/static/django_tables2/themes/paleblue/css/screen.css檢索screen.css文件。如果css文件沒有加載,那麼你可能會設置一些錯誤的設置。

相關問題