[英]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.