简体   繁体   English

django + nginx无法加载静态文件

[英]the django + nginx can't load staticfiles

recently when i use the { %load staticfiles % } in my django app.i just found that it shows like this picture as follows: enter image description here 最近,当我在django应用程序中使用{%load staticfiles%}时,我发现它显示如下图所示: 在此处输入图像描述

。the settings files are like this: 。设置文件如下:

STATIC_DIR = os.path.join(BASE_DIR,'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = [STATIC_DIR, ]
STATIC_ROOT = os.path.join(BASE_DIR, "static/")

and the file's directory are like follows: 文件的目录如下:

web1->web1->settings.py
we1->static->img->ocen.jpg

the base.html are like this: base.html是这样的:

<!DOCTYPE html>

{ % load staticfiles % }

<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>

<img src="{ % static "img/ocen.jpg" % }" alt="show picture">

</body>
</html>

the ngix configure file are like this: ngix配置文件如下所示:

location /static/ {
        alias /home/yumo/web1;
    }

To find the reason ,I try as follows:first , i konck :domainname/static/img/ocen.jpg in the browser. 为了找到原因,我尝试如下:首先,在浏览器中,我知道:domainname / static / img / ocen.jpg。 I can see my ocen.jpg in the browser. 我可以在浏览器中看到我的ocen.jpg。 second: i just create the django app in my local virtual machine without using uwsgi and nginx. 第二:我只是在本地虚拟机中创建了django应用程序,而没有使用uwsgi和nginx。 i can use the { % load staticfiles %} normally to achieve my aims. 我通常可以使用{%load staticfiles%}来实现我的目标。 i just sincerely wan't someone give me some useful advise,thank you! 我真诚地希望没有人给我一些有用的建议,谢谢!

In django template tags look like this {% tag %} Please note that there is no space between { and % . 在django模板中, 标签看起来像这样{% tag %}请注意{%之间没有空格。

So instead of 所以代替

{ % load staticfiles % }
<img src="{ % static "img/ocen.jpg" % }" alt="show picture">

you should do: 你应该做:

{% load staticfiles %}
<img src="{% static 'img/ocen.jpg' %}" alt="show picture">    

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

相关问题 django不会从statifiles_dirs加载静态文件 - django won't load staticfiles from statifiles_dirs 使用前缀部署django app时,不会加载静态文件 - Staticfiles don't load when deploying django app with prefix 将 Django 应用程序部署到 Heroku 无法加载静态文件 - Deploying Django App to Heroku Cant load Staticfiles Django 不加载静态文件 ValueError(“缺少 &#39;%s&#39; 的静态文件清单条目”% clean_name) - Django doesn't load static files ValueError(“Missing staticfiles manifest entry for '%s'” % clean_name) 我可以在Debug = True时强制Django静态文件在本地加载哈希文件名吗? - Can I force Django staticfiles to load hashed filenames locally while Debug=True? 在Django中,我的staticfiles是大文件(超过500K个文件)的方式,如何划分负载? - In Django, my staticfiles are way to large (over 500K files), how can I divide the load? 为什么 Django 不在生产中提供静态文件? - Why isn't Django serving staticfiles in production? Django静态文件未在生产中加载 - Django staticfiles aren't loading in production 如何将 docker django 应用程序中的静态文件提供给托管的 nginx - How to serve staticfiles from docker django app to hosted nginx Django 调试工具栏 - 无法使其工作(配置不当:STATICFILES_DIRS ...) - Django debug-toolbar - Can't make it work (ImproperlyConfigured: The STATICFILES_DIRS …)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM