如何在模板中查看“models.FilePathField”存储的文件?

时间:2013-06-25 10:14:42

标签: django django-models path django-views django-settings

我发现了另外两个类似于我的问题,但我无法弄明白......抱歉...... !!!

这里有一个我的models.py:

class Brano( models.Model ):
    titolo = models.CharField( max_length=39 )
    testo = models.TextField( max_length=1000 )

    locandina = models.FilePathField( path="C:/Users/Federico/Google Drive/Umore/apps/Database/static/Brani/Locandina", recursive=True )
    copertina = models.FilePathField( path="C:/Users/Federico/Google Drive/Umore/apps/Database/static/Brani/Copertina", recursive=True )

    data_inserimento = models.DateField( null=True, verbose_name="data d'inserimento" )
    anno = models.ForeignKey( Anno )
    durata = models.CharField( max_length=5 )
    albums = models.ManyToManyField( Album )
    artisti = models.ManyToManyField( Artista )
    generi = models.ManyToManyField( Genere_Brano )
    colonne_sonore = models.ManyToManyField( Film, blank=True )
    def __unicode__(self):
        return self.titolo
    class Meta:
        verbose_name_plural = "Brani"
        ordering = ("-anno", )

这里是我的views.py:

的def
def brano(request, id):
    brano = get_object_or_404( Brano, pk=id )
    return render_to_response('Brano.html', { 'brano': brano })

这是我模板的一部分:

<img class="w660 h400" src="{{ brano.locandina }}">

我已经尝试了我在其他两个问题中发现的内容。我无法理解如何将模板传递给相对路径而不是绝对路径。你能帮我吗...... ??!

0 个答案:

没有答案