如何在Django服务器的缩进行中显示user_list?

时间:2018-10-09 15:04:25

标签: python django python-3.x

我有一个问题,我有一个网站可以显示用户,但它不以直线显示用户,而是以倒金字塔显示用户。这可能是因为我正在使用django-filter应用程序,但它不应该造成这样的问题。最后的配置文件(尤其是在移动视图中)重叠并拖动。随着配置文件的增加,情况变得更糟。可以将个人资料或用户列表直线对齐吗?

请在下面找到我的代码。

filters.py(用于djang-filters应用)

  import django_filters
  from userprofile.models import UserProfiles

class UserProfilesFilter(django_filters.FilterSet):
    class Meta:
       model = UserProfiles
       fields = ['gender', 'age', 'Nationality','preference', 'Country', 
       'City']

views.py

@login_required
def profiles_list(request):
    filter = UserProfilesFilter(request.GET, queryset = 
    UserProfiles.objects.all().order_by('-pub_date'))
    return render(request,"userprofile/user_list.html", {'filter': filter})

user_list.html

  {% extends 'base.html' %}
   {% block content %}
   {% load static %}
   {% load bootstrap %}




<div class="container">

<form class="form-horizontal col-md-4 col-lg-4 col-sm-4" action="" 
 method="get">
      {{ filter.form|bootstrap}} {% csrf_token %}
      <input type="submit" value='search'/>
   </form>

 {% for profile in filter.qs %}

 <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12">


  <hr>

  <a href="{% url 'userprofile:profileview' profile.user %}"><h3>{{ 
  profile.user }}</h3></a>
  <br>
 <img src="{{ profile.image.url }}" class="rounded mx-auto d-block img- 
responsive float-left" style= "max-height: 100px; max-width: 100px;">
 <br><br>
 <br><br> <br>
 <div class="font-weight-normal text-justify">
 Gender: {{ profile.gender }}
 <br>
 Country: {{ profile.Country }}
 <br>
 Description: {{ profile.summary }}
 <br>
 Preferences: {{ profile.preference }}
 <br><br>

  {% endfor %}
   </div>
   </div>
   <!--adnow ad-->
   <script type="text/javascript">
  (sc_adv_out = window.sc_adv_out || []).push({
    id : "575193",
   domain : "n.ads1-adnow.com"
   });
   </script>
  <script type="text/javascript" src="//st-n.ads1-adnow.com/js/a.js"> 
</script>
<div id="SC_TBlock_575193" class="SC_TBlock">loading...</div>
<!--adnow finishes-->





 {% endblock %}

1 个答案:

答案 0 :(得分:0)

由于应在循环中启动div标记,因此应在每个for循环中关闭它们。

更改:

{% endfor %}
</div>
</div>

收件人:

</div>
</div>
{% endfor %}