简体   繁体   English

无法在 django 中加载 static 文件

[英]cant load static file in django

I copied a HTML page with many images and javascript codes.我复制了一个 HTML 页面,其中包含许多图像和 javascript 代码。

I created the static folder and did everything that is needed, and when I'm tying to load the source with static tag such as:我创建了static folder并做了所有需要的事情,当我想用static tag加载源时,例如:

<link rel="stylesheet" type="text/css" href="{% static 'styles/bootstrap4/bootstrap.min.css' %}">

I'm still getting an error:我仍然收到错误消息:

GET http://127.0.0.1:8000/static/styles/bootstrap4/bootstrap.min.css net::ERR_ABORTED 404 (Not Found)

All it did is to add static in the url and I dont understand why?它所做的只是在 url 中添加static我不明白为什么?

I cant find how to load jinja in pycharm so my tags are white.我找不到如何在 pycharm 中加载 jinja,所以我的标签是白色的。

Have you looked at the Django Documentation ?您看过Django 文档吗?

Serving the files提供文件

In addition to these configuration steps, you'll also need to actually serve the static files.除了这些配置步骤之外,您还需要实际提供 static 文件。

During development, if you use django.contrib.staticfiles, this will be done automatically by runserver when DEBUG is set to True (see django.contrib.staticfiles.views.serve()).在开发过程中,如果您使用 django.contrib.staticfiles,这将在 DEBUG 设置为 True 时由 runserver 自动完成(参见 django.contrib.staticfiles.views.serve())。

This method is grossly inefficient and probably insecure, so it is unsuitable for production.这种方法效率极低并且可能不安全,因此不适合生产。

See Deploying static files for proper strategies to serve static files in production environments.有关在生产环境中提供 static 文件的正确策略,请参阅部署 static 文件。

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

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