如何在html中修复动态图片标签

时间:2019-10-15 13:51:56

标签: python django django-rest-framework

我正在用HTML渲染图像标签,但出现类似错误 型号:

class Events(models.Model):
    event_author=models.ManyToManyField(Author)
    event_title=models.CharField(max_length=300)
    event_title_image = models.ImageField(upload_to='images/', blank=True, null=False)
    event_description=models.TextField(blank = True)
    event_image_description = models.ImageField(upload_to='images/', blank=True, null=True)
    event_release_date = models.DateField(null="false")

HTML页面代码

{% for events in events %}
    <div>

        <h2><a href="">{{ events.event_title }}</a></h2>
        <p>published: {{ events.event_release_date }}</p>

        <p>{{ events.event_description|linebreaksbr }}</p>
        <img src={{ events.event_title_image }} alt="diagram"  " />

观看次数

def index(request):
    return render(request, 'polls/home.html', {})

"model class name and function name should not be samm"
def Event(request):
    events=Events.objects.filter(event_release_date__lte=timezone.now()).order_by('event_release_date')
    return render(request, 'polls/events.html', {'events':events})

URls文件

from django.contrib import admin
from django.conf import settings # new
from django.conf.urls.static import static
from django.conf.urls import url, include

from django.conf.urls.static import static
from django.urls import path, include



urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include("polls.urls")),



]+static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)

我希望图像需要显示在网页中,然后出现类似错误

enter image description here

0 个答案:

没有答案