5
5
50VAJJ2017-07-06 21:03:45
Django
50VAJJ, 2017-07-06 21:03:45

Ul li and python django?

Hello. Can django affect css?
Here are the codes -
models

class Tag(models.Model):
    name = models.CharField(verbose_name='Название тега', max_length=50, default='')
    alias = models.SlugField(verbose_name='Alias тега', default='')

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = 'Tag'
        verbose_name_plural = 'Tags'

views
def mainPage(request):
    tag = Tag.objects.all()
    return render(request, 'mainPage/index.html', locals())

HTML
<div class="tags">
                {% for value in tag %}
                <ul>
                    <li><a href="">{{value.name}}</a></li>
                </ul>
                {% endfor %}
            </div>

and CSS
.tags{
    width: 100%;
    height: 100px;
    margin: 15px auto;

    text-align: center;
}
.tags ul{
    text-align:center;
}
.tags li{
    display:inline-block;

    margin: 5px 10px;

    cursor: pointer;
    transition: all .2s ease-in-out;
    text-align: center;

    border-radius: 3px;
    background-color: #44c1b9;
}
.tags li:hover{
    transform: scale(0.95);
}
.tags a{
    display: block;

    padding: 10px;

    font-size: 17px;
}

Everything works perfectly, except that all the tags are centered down one after the other. When I just made up a template, this was not the case and text-align:center worked perfectly. And now each tag is located in the center of the page and goes down one by one.
This is most likely due to the for loop in the HTML document. The problem appeared as soon as I added it.
How can it be solved?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Astrohas, 2017-07-06
@50VAJJ

<div class="tags">
                {% for value in tag %}
                <ul>
                    <li><a href="">{{value.name}}</a></li>
                </ul>
                {% endfor %}
            </div>

replaced by
<ul class="tags">
                {% for value in tag %}

                    <li><a href="">{{value.name}}</a></li>

                {% endfor %}
        
</ul>

S
sim3x, 2017-07-06
@sim3x

No, they don't do that because MVT
Study pep8 - you don't name functions correctly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question