0
我創建了一個網頁Python-Django
在application.I文件models.py設置album_logo領域,我試圖通過Python Shell中上傳圖片的URL使用的代碼在Django應用程序的圖像不工作
>>>from music.models import Album, Song
>>>Album.objects.all()
[]
>>>a = Album(artist="Taylor Swift", album_title="Red", genre=" Country", album_logo="http://carywebdesigns.com/wp-content/uploads/2015/02/www2.jpg")
>>>a.save()
>>>a.artist
'Taylor Swift'
>>>a.album_title
'Red'
>>>a.id
1
>>>a.pk
1
模型。 PY
from django.db import models
# Create your models here.
class Album(models.Model):
artist = models.CharField(max_length=250)
album_title = models.CharField(max_length=500)
genre = models.CharField(max_length=100)
album_logo = models.CharField(max_length=1000)
def __str__(self):
return self.album_title + ' - ' + self.artist
我使用python manage.py runserver
運行此代碼,我得到了正確的answer.But未加載圖像。 而我有2個模板文件。 的index.html
{% if all_albums %}
<h3>Here are all my Albums:</h3>
<ul>
{% for album in all_albums %}
<li><a href="/music/{{ album.id }}/">{{ album.album_title }}</a></li>
{% endfor %}
</ul>
{% else %}
<h3>You don't have any albums</h3>
{% endif %}
detail.html
<img src="{{ album.album_logo }}">
<h1>{{ album.album_title }}</h1>
<h3>{{ artist }}</h3>
<ul>
{% for song in album.song_set.all %}
<li>{{ song.song_title }} - {{ song.file_type }}</li>
{% endfor %}
我怎麼能提前解決這個problem.Please幫助me.Thanks ..
你怎麼顯示圖像?請分享模板代碼 – Kroenig