简体   繁体   English

图片上传Django Admin

[英]Image Upload Django Admin

I'm new to Django and need to upload an image through the admin to use on a portfolio site I am making. 我是Django的新手,需要通过管理员上传图片才能在我正在制作的投资组合网站上使用。 I am using sorl-thumbnail to have the images show up on the front end, however I don't know how to properly call them once they are uploaded or where to upload them to. 我正在使用缩略图缩略图将图像显示在前端,但是我不知道一旦上传图像或将图像上传到何处,如何正确调用它们。 Here is my models.py : 这是我的models.py

from django.db import models

# Create your models here.
class CaseStudy(models.Model):
    title = models.CharField(max_length=150)
    description = models.TextField()
    picture = models.ImageField(upload_to="static")

    def __unicode__(self):
        return self.title #makes title the link in admin

And here is an example how I use sorl-thumbnail in template: 这是一个示例我如何在模板中使用sorl-thumbnail:

{% thumbnail item.image "100x700" as im %}
<img style="margin:{{ im|margin:"100x700" }}" src="{{ im.url }}" width="{{ im.x }}"     height="{{ im.y }}">
{% endthumbnail %}

Any help would be greatly appreciated because I am a Django noob. 任何帮助将不胜感激,因为我是Django noob。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM