我想在我的网站上显示图像。我一直在浏览Django文档和其他帖子在stackoverflow,但我没有得到这个工作。
我有一个图像名称'under-construction.jpg'。它住在/home/di/mysite/myapp/static/images
目录中。如何在Django的网页上显示图像?
我有这样的一个模板:
<img src="{{ STATIC_URL }}images/under_construction.jpg" alt="Hi!" />
在我的views.py
我有这样的:
def under_construction(request):
return render(request, 'under_construction.html')
在我的settings.py,我有这样的:
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'/home/di/mysite/myapp/static',
'/home/di/mysite/myapp/static/images',
)
我执行./manage.py collectstatic
,它把大量的文件放在/home/di/mysite/admin
和/home/di/mysite/images
。我必须做些什么让我的形象出现?
STATIC_ROOT ='/home/di/mysite/myapp' – shiva
http://stackoverflow.com/questions/1179453/django-and-serving-static-files可能的重复 –
http://stackoverflow.com/questions/10792256/show-picture-in-django/10792318可能的重复#10792318 – lciamp