Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Django image gallery

I am looking to create a portfolio using Django. I have tried using ImageField but it only allows me to upload and replace 1 photo.

I am new to Python and Django programming. How would I create a model to upload multiple images and show them in a gallery? Thanks.

like image 754
Carl W. Avatar asked Jun 23 '12 01:06

Carl W.


2 Answers

You can try django-galleryfield. BTW, I am the author of the package.

like image 78
Dzhuang Avatar answered Oct 05 '22 23:10

Dzhuang


Just put the following code in your gallery template.

{% for image in images %}
                {% if forloop.first %}
                    <div class="row ">
                {% endif %}
                <div class="col-lg-4 col-md-4 col-12" >
                    <div class="text-center mt-2">
                        <img src="{{image.image.url}}"height="70%" width="70%" class="img-thumbnail" alt="...">
                    </div>
                </div>
                {% if forloop.counter|divisibleby:3 %}
                    </div>
                    <div class=row>
                {% endif %}
                {% if forloop.last %}
                        </div>
                {% endif %}
{% endfor %}
like image 42
Akram Narejo Avatar answered Oct 05 '22 23:10

Akram Narejo