因此,我在这里看到了很多教程,其中解释了如何做,但是无论我如何更改,静态文件似乎都不会加载。这就是我的文件看起来像atm
settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [os.path.join(PROJECT_ROOT, "static"),'']
job_app / urls.py
urlpatterns = [
path('', main, name='index'),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>JobPortal - Free Bootstrap 4 Template by Colorlib</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
{% load static %}
<link href="https://fonts.googleapis.com/css?family=Nunito+Sans:200,300,400,600,700,800,900" rel="stylesheet">
<link rel="stylesheet" href="{% static 'css/open-iconic-bootstrap.min.css' %}">
<link rel="stylesheet" href="{% static 'css/animate.css' %}">
<link rel="stylesheet" href="{% static 'css/owl.carousel.min.css' %}">
<link rel="stylesheet" href="{% static 'css/owl.theme.default.min.css' %}">
<link rel="stylesheet" href="{% static 'css/magnific-popup.css' %}">
<link rel="stylesheet" href="{% static 'css/aos.css' %}">
<link rel="stylesheet" href="{% static 'css/ionicons.min.css' %}">
<link rel="stylesheet" href="{% static 'css/bootstrap-datepicker.css' %}">
<link rel="stylesheet" href="{% static 'css/jquery.timepicker.css' %}">
<link rel="stylesheet" href="{% static 'css/flaticon.css' %}">
<link rel="stylesheet" href="{% static 'css/icomoon.css' %}">
<link rel="stylesheet" href="{% static 'css/style.css' %}">
</head>
<body>
jobber / urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('job_app.urls'))
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
答案 0 :(得分:2)
以下配置对我有用。 Django只需要两件事。
从urls.py中删除静态urlpatterns
。仅在settings.py中定义STATIC_URL
和STATICFILES_DIRS
并删除STATIC_ROOT
。
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)