django中导入css,js文件链接时遇到问题

时间:2018-09-22 14:14:03

标签: python css django

我是Django 2.11.1中的新手,并使用macbook作为平台。我在将css,图像和js链接到Django模板时遇到问题,我尝试了几种方法来更改setting.py中的代码,还是运行``python manage.py collectstatic --noinput'',结果是我可以找到路径的css和js文件是正确的,我可以在“ http://127.0.0.1:8000/become-a-host/index”中找到它们,但是它们对网站的视觉效果没有影响,显然它们不起作用,我不知道知道为什么。 这是我的项目结构 sentiment_analysis

|-zeta
| |-.vscode
| |-users
| |-manage.py
| |-venv
| |-static
| |-zeta
| | |-_pycache_
| | |-__init__.py
| | |-setting.py 
| | |-wsgi.py 
| | |-urls.py 
| |-advertising
| | |-_pycache_
| | |-migrations
| | |-__init__.py 
| | |-admin.py 
| | |-models.py 
| | |-tests.py 
| | |-urls.py 
| | |-views.py 
| | |-tests.py 
| | |-app.py
| |-templates
| | |-advertising
| | | |-index.html
| | |-users 

setting.py 

STATIC_URL = '/static/'
STATICFILES_DIRS = (
    '/Users/zachary/lecture/9900/zeta/static/',
)
TEMPLATE_DIRS = ( 
    '/advertising/templates', 
)
STATIC_ROOT = '/Users/zachary/lecture/9900/zeta/static_root/'

url.py
urlpatterns += staticfiles_urlpatterns()

base.html
 <meta charset="utf-8">
  {% load staticfiles %}
  <link rel="stylesheet" href="{% static 'css/icomoon.css'%}"  type='test/css'/>
  <link rel="stylesheet" href="{% static 'css/style.css'%}" type='test/css'/>
  <script src="{% static 'js/jquery.min.js' %}"></script>
  <script src="{% static 'js/jquery-migrate-3.0.1.min.js' %}"></script>
  <script src="{% static 'js/popper.min.js' %}"></script>

1 个答案:

答案 0 :(得分:0)

它们没有视觉效果,因为您拼写了CSS文件的mime类型:

from PyQt5 import QtCore, QtGui, QtWidgets

class SpotlightWidget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(SpotlightWidget, self).__init__(parent, QtCore.Qt.WindowStaysOnTopHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.setAttribute(QtCore.Qt.WA_TransparentForMouseEvents)
        self.showFullScreen()
        self.setMouseTracking(True)
        self.center = QtCore.QPoint()

        self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
        self.quitAction = QtWidgets.QAction("Salir", self,shortcut="Ctrl+Q", triggered=self.close)
        self.addAction(self.quitAction)

    def mouseMoveEvent(self, event):
        self.center = event.pos()
        self.update()
        super(SpotlightWidget, self).mouseMoveEvent(event)

    def paintEvent(self, event):
        painter = QtGui.QPainter(self)
        painter.setPen(QtCore.Qt.NoPen)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        painter.setBrush(QtGui.QColor(108, 119, 125, 220))
        radius = 100
        path = QtGui.QPainterPath()
        if not self.center.isNull():
            path.moveTo(self.center + radius/2*QtCore.QPoint(1, 0))
            path.arcTo(QtCore.QRectF(self.center - radius/2*QtCore.QPointF(1, 1), radius*QtCore.QSizeF(1, 1)), 0, 360)
        path.addRect(QtCore.QRectF(self.rect()))
        painter.drawPath(path)


if __name__ == '__main__':
    import sys

    app = QtWidgets.QApplication(sys.argv)
    w = SpotlightWidget()
    w.show()
    sys.exit(app.exec_())

应该是:

type='test/css'