简体   繁体   English

CSS文件未加载(Django,Python)

[英]CSS file not loading (Django, python)

Here's the code I have: 这是我的代码:

In the HTML file: 在HTML文件中:

<link rel="stylesheet" href={% static 'css.css' %}" >

In settings.py: 在settings.py中:

 STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)

The css.css file is located in the static directory which is in the same directory as manage.py , So why isn't the css file loading? css.css文件位于与manage.py相同目录下的静态目录中,那么为什么不加载css文件呢?

There is also a js file which doesn't seem to be loading either, and it's in the same directory as the CSS file and I'm loading it in with the same method as the CSS file. 还有一个似乎也未加载的js文件,它与CSS文件位于同一目录中,而我使用与CSS文件相同的方法加载该文件。

Also, my pc isn't currently connected to WiFi, in case it makes a difference. 另外,我的电脑目前未连接到WiFi,以防万一。 I'm working with localhost. 我正在使用本地主机。

Have you configured your Static files URL. 您是否配置了静态文件URL。 According to best practice 根据最佳实践

STATIC_URL = '/static/'

Actually the above is too little information to help anyway. 实际上,以上信息太少,无法提供帮助。 Can you tell us the application environment (production/development) etc because there are specific configurations for each in Django. 您能否告诉我们应用程序环境(生产/开发)等,因为Django中每个应用程序都有特定的配置。 Also please provide code using the code markup. 另外,请使用代码标记提供代码。 Assuming you are using Django 1.11, read this for a better understanding or better yet see a tutorial for beginners 假设您使用的是Django 1.11,请阅读此书以获得更好的理解,或者更好地阅读初学者教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM