Sunday, May 17, 2020

Re: How to create custom tag - break for tamplate?

Sergei, you just to have put an conditional flag. It could be defined in your view. Example:
flag_ = 0
if pedrito > 16  
   flag_ = 1

and flag_ send it in context 

in template you must include:
{%  if flag_ == 0 %}
      brek
      etc.

Gabriel Araya Garcia
GMI - Desarrollo de Sistemas Informáticos
99.7721.15.70



El dom., 17 may. 2020 a las 11:10, Sergei Sokov (<sokov.tlt@gmail.com>) escribió:

views.py

class MyClassCreateView(LoginRequiredMixin, CustomSuccessMessageMixin, CreateView):
model
= MyClass
template_name
= 'mypage.html'
form_class
= MyClassForm
success_url
= reverse_lazy('mypage')
success_msg
= 'сохранён'
def get_context_data(self, **kwargs):
    kwargs
['list_mylist'] = MyClass.objects.all()
    list_mylist
= kwargs['list_mylist']
   
for i in list_mylist:
       
if i.author == self.request.user:
           
print('my_button')
            kwargs
['my_button'] = True
           
break
   
return super().get_context_data(**kwargs)

template

        {% if my_button %}
       
{% for i in list_mylist %}
             
{% if request.user == i.author %}
               
<a class="btn btn-primary" href="#" role="button">
                 
кнопка первая
               
</a>
             {% endif %}
       {% endfor %}
{% else %}
    <button type="button" class="btn btn-primary mr-4" data-toggle="modal" data-target="#class">
          кнопка вторая
        </
button><br>
   
{% endif %}



суббота, 16 мая 2020 г., 20:05:01 UTC+2 пользователь Sergei Sokov написал:
Hi
I would like abort a loop in my template.
How to create custom tag - break for tamplate?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5f05fc6e-13a0-47ba-be33-9c860dc48dee%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKVvSDDFFeTzd_MhvK4ebD9eGRd%2BJ%2Btg8gVy9_Sdv_Y8HnTmzA%40mail.gmail.com.

No comments:

Post a Comment