从移动设备上传图像时出错?

时间:2018-08-20 19:20:14

标签: python django python-3.x django-models django-views

这是我的models.py文件

class Report_item(models.Model):
    owner = models.ForeignKey(settings.AUTH_USER_MODEL)
    title = models.CharField(max_length=255, help_text='*Title for the post e.g. item identity')
    item_type = models.CharField(default="", max_length=100,
                                 help_text='*Enter the item name you found e.g. Marksheet,key,wallet')
    location = models.CharField(max_length=60, help_text='*Enter the address/street where you find this item')
    city = models.CharField(max_length=60, help_text='*Enter the city name')
    date = models.DateTimeField(default=timezone.now)
    Description = models.TextField(blank=True,null=True,help_text='*Enter full description about item')
    publish = models.BooleanField(default=False)

    image = models.ImageField(default="add Item image",
                             help_text='*Please uplocad a item image to identify by the owner')

    def __str__(self):
        return self.title + "      " + str(self.publish)

    def get_absolute_url(self):
        return reverse('feed:detail', kwargs={'pk': self.pk})

    class Meta:
        ordering = ["-date"]

这是我的上传视图:

class ReportCreate(generic.CreateView):
    model = Report_item
    fields = ['title', 'item_type', 'location', 'city', 'image', 'Description']

    def form_valid(self, form):
        self.object = form.save(commit=False)
        self.object.owner = self.request.user
        self.object.save()
        return FormMixin.form_valid(self, form)

这是我的view.py文件

def IndexView(request):
    query_list = Report_item.objects.filter(publish=True)
    query = request.GET.get('q')
    if query:
        query_list = query_list.filter(Q(title__icontains=query) |
                                       Q(item_type__icontains=query) |
                                       Q(city__icontains=query) |
                                       Q(location__icontains=query) |
                                       Q(Description__icontains=query)).distinct()

    context = {
        "object_list": query_list
    }
    return render(request, "feed/index.html", context)

这是我的供稿/索引文件

{% for obj in object_list %}
      <div class="thumbnail" onclick="window.open('{% url 'feed:detail' obj.id %}','mywindow');" style="cursor: pointer;">
          <div class="row">
              <div class="col-md-9">
                  <table class="mytable table-responsive">
                        <tr><td class="my-td-item">Title</td><td>{{ obj.title }}</td></tr>
                        <tr><td class="my-td-item">Item Type</td><td>{{ obj.item_type }}</td></tr>
                        <tr><td class="my-td-item">Location</td><td>{{ obj.location }}</td></tr>
                      <tr><td class="my-td-item">City</td><td>{{ obj.city }}</td></td></tr>
                  </table>
              </div>
              <div class="col-md-3">
                  <img class="img-responsive center" src="{{ obj.image.url }}" alt="backmyitem" width="80" height="100" style="margin: 0 auto;">
                  <br><b><p style="font-size: 10px;text-align:center;">Posted Date</b><br>{{ obj.date }}</p>
              </div>
          </div>
          <div class="row">
              <div class="more-detail-div col-md-12">
                  <a class="">More Detail</a>
              </div>
          </div>
      </div>
      {% endfor %}

当我从笔记本电脑中的应用程序中上传图像时,该图像成功上传,并且图像也显示在feed / index.html中,但与此同时,当我使用手机或任何其他移动设备上传该图像时,它导致错误。即使成功上传了图片,但在admin部分以及供稿页面中也成功上传了图片,其名称和路径也正确,但是在admin和索引文件中均未显示。新标签,然后显示403禁止。

ngin中的错误

2018/08/20 19:34:37 [error] 4498#4498: *89 open() "/home/ubuntu/media/153476127499997915256.jpg" failed (13: Permission denied), client: 103.201.$

x错误日志如下:

0 个答案:

没有答案