django 文档,提供静态文件,3 个简单步骤?没有
https://docs.djangoproject.com/en/1.3/howto/static- files/
尝试提供静态文件,我被放在上面的链接上。
该链接告诉我在开发中提供静态文件时
- 将静态文件放在可以找到的位置,“home/jamie/mysite/static/” 完毕!
2.确保 django.contrib.staticfiles 包含在您的 INSTALLED_APPS 中。 对于本地开发,如果您使用 runserver...您已完成设置。 完毕!
3.您可能需要在模板中引用这些文件。最简单的方法是使用包含的上下文处理器,它允许模板代码,例如:
<img src="{{ STATIC_URL }}images/hi.jpg" />
完成!
哇,这看起来太简单了,肯定行不通, 可悲的是,没有。
当我检查时,{{ STATIC_URL }}等于无。现在STATIC_URL默认是none,因此这些指令没有做任何事情。当然我做错了什么,而 django 文档是正确的。但我不知道在这三个简单的步骤中我哪里出了问题。
https://docs.djangoproject.com/en/1.3/howto/static-files/
Trying to serve static files i was put on to the above link.
The link tells me when serving static files in development
- Put your static files where they will be found, 'home/jamie/mysite/static/'
Done!
2.Make sure that django.contrib.staticfiles is included in your INSTALLED_APPS.
For local development, if you are using runserver...you’re done with the setup.
Done!
3.You’ll probably need to refer to these files in your templates. The easiest method is to use the included context processor which allows template code like:
<img src="{{ STATIC_URL }}images/hi.jpg" />
Done!
Wow, that seems too simple, surely it wouldn't work,
and sadly, no.
{{ STATIC_URL }} when i checked, equals None. Now STATIC_URL by default is none, therefore these instruction haven't done a thing. Surely i've done something wrong and the django documentation is right. But i cant figure out where in the three simple steps i've gone wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在
settings.py
中设置STATIC_URL = '/static/'
。Try setting
STATIC_URL = '/static/'
in yoursettings.py
.