from django.db import models
from PIL import Image
class News(models.Model):
news_heading = models.CharField(max_length=50)
news_date = models.DateTimeField()
news_details = models.CharField(max_length=200)
image_one = models.ImageField(upload_to="images/news",blank=True)
image_one_height = models.BigIntegerField(blank=True,default=300)
image_one_width = models.BigIntegerField(blank=True,default=300)
image_two = models.ImageField(upload_to="images/news",blank=True)
image_two_height = models.BigIntegerField(blank=True,default=300)
image_two_width = models.BigIntegerField(blank=True,default=300)
def __str__(self):
return self.news_heading
这是我的模型。py
from django.shortcuts import render
from .models import News
# Create your views here.
def news_view(request):
news = News.objects.order_by('-id')
context = {
'news':news
}
return render(request,'news/news.html',context)
这是我的view.py,我应该做些什么才能使图像显示正确。 Potrait图像显示向左旋转。如何使它们显示正确。
{% extends "homepage/navbar.html" %}
{% load staticfiles %}
{% block content %}
<style type="text/css">
img {
image-orientation: from-image;
}
</style>
<section class="mbr-section content5 cid-rjuc1r5LAi" id="content5-w">
<div class="container">
<div class="media-container-row">
<div class="title col-12 col-md-8">
<h2 class="align-center mbr-bold mbr-white pb-3 mbr-fonts-style display-2"><span style="font-weight: normal;">
NEWS & UPDATES
</span></h2>
</div>
</div>
</div>
</section>
<section>
<div class="container">
<div class="row">
{% for update in news %}
<dir class="col-md-10" style="border-left: 2px solid red; border-bottom: 2px solid #3e4095">
<h2>{{ update.news_heading }}</h2>
{% if update.image_one %}
<img src="{{ update.image_one.url }}" width="{{update.image_one_width}}" height="{{update.image_one_height}}">
{% endif %}
{% if update.image_two %}
<img src="{{ update.image_two.url }}" width="{{update.image_two_width}}" height="{{update.image_two_height}}">
{% endif %}
<p>{{ update.news_details }}</p>
</dir>
{% endfor %}
</div>
</div>
</section>
{% endblock %}
这是模板代码。
我应该怎么做才能使图像显示正确。 Potrait图像显示向左旋转。如何使它们显示正确。