問題是我得到一個破碎的圖像類型。我的代碼如下:圖像看起來像一個破碎的圖像
settings.py中我有
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
SETTINGS_DIR = os.path.dirname(__file__)
PROJECT_PATH = os.path.join(SETTINGS_DIR, os.pardir)
PROJECT_PATH = os.path.abspath(PROJECT_PATH)
TEMPLATE_DIRS = [os.path.join(PROJECT_PATH, 'templates')]
MEDIA_ROOT = '/home/username/work_station/project1/media/static/pic'
MEDIA_URL = '/media/'
PROJECT_ROOT = os.path.join(os.path.dirname(__file__), '..')
SITE_ROOT = PROJECT_ROOT
STATIC_ROOT = os.path.join(SITE_ROOT, 'static')
我的models.py
class Image(models.Model):
post = models.ForeignKey(Post)
image = models.ImageField(upload_to='static/pic/', default = None)
description = models.CharField(max_length=100)
def __unicode__(self):
我的觀點
class IndexListView(ListView):
template_name = "dashboard.html"
context_object_name = 'latest_pictures'
def get_queryset(self):
return Image.objects.all()
return str(self.image)
我的模板:dashboard.html
{% for latest in latest_pictures %}
{% load staticfiles %}
<div><img src="{{ MEDIA_URL }}{{ latest.image }}"></div>
{% endfor %}
什麼是斷開的鏈接? – doniyor
什麼是負責從/ media /提供文件? –