0

我的模板不起作用,无法获取静态文件,但我做了一切。我只是无法获取 style.css 但已加载其他文件。只有样式和一些js文件没有加载但路径没有错。请帮我

这是我的文件夹和项目树的图像

静态和媒体设置。

STATIC_URL = '/temfiles/'
MEDIA_URL = '/mediafiles/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/uploads/')
X_FRAME_OPTIONS = 'SAMEORIGIN'

我的项目 URL 文件

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('blog.urls')),
    path('froala_editor/', include('froala_editor.urls'))

]
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL,
                      document_root=settings.MEDIA_ROOT)

我的应用程序 URL 文件

urlpatterns = [
    path('', views.index, name = 'index'),
    path('<slug:slug>/', views.post_detail, name='Post Detail')
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

我的视图文件

def index(request):
    Post_list = BlogPost.objects.all()
    template_name = 'front/index.html'
    return render(request, template_name,{"Post_list":Post_list})



def post_detail(request):
    return render(request, 'front/post_detail.html')

我的基本模板 CSS 示例

   {% load static %}
  <link rel="stylesheet" type="text/css" href="{% static 
  'front/css/style.css' %}">

静态目录树图像

带有打开文件夹的静态目录树

浏览器检查终端图片

在浏览器中设置样式 CSS URL

MY urls.py 用于静态和媒体根目录

4

0 回答 0