首页 > 解决方案 > CSS not loaded with net::ERR_ABORTED 404 error

问题描述

When I updated from Symfony 3.4 to 4.0 and displayed it in a browser, the following error appeared.
Symfony/assets are also installed, I tried the code below but it didn't work.
Is there anything else you can think of?
Directory

src/
 └ Resources/
      ┝ public/css/style.css
           └ view/layout.html.twg
               

Try Code

<link rel="stylesheet" href="{{absolute_url(asset('css/style.css'))}}">
<link rel="stylesheet" href="{{ asset('css/style.css') }}">
<link rel="stylesheet" href="../public/css/style.css">

Version
Symfony 4.0.15
PHP 7.3
symfony/asset 4.0.15

标签: phpsymfony

解决方案


I moved the css directory from within the Resources/public directory to inside the public/ directory in the project and the code below fixed the issue.

<link rel="stylesheet" href="{{ asset('/css/style.css') }}">

推荐阅读