V
V
Vladislava2021-12-30 10:29:02
Django
Vladislava, 2021-12-30 10:29:02

Why isn't it rendered in Django template?

In general, you need to output k in user_profile. It was successfully displayed in the task_list, but it is not displayed in the user_profile. What is the reason? Views

class TaskList(LoginRequiredMixin, ListView):
    model = Task
    context_object_name = 'tasks'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['tasks'] = context['tasks'].filter(user=self.request.user)
        context['count'] = context['tasks'].filter(complete=False).count()
        context['k'] = context['tasks'].filter(complete=True).count()

        search_input = self.request.GET.get('search-area') or ''
        if search_input:
            context['tasks'] = context['tasks'].filter(title__icontains=search_input)
        context['search_input'] = search_input

        return context


user_profile.html
{% extends 'base/main.html' %}
{% load static %}
{% block content %}

    <div class="header-bar">
        <h1>Profile</h1>
        
        <a href="{% url 'tasks' %}">&#8592; Back</a>
        
    </div>
    
    <div class="card-body">
    {% if user.profile.profile_pic %}
      <img src="{{ profile.profile_pic.url }}" height=100 width=100><br><br>
    {% else %}
      <img src="{% static 'base\images\profile\user.png' %}" height=100 width=100><br><br>
    {% endif %}
      <p><strong>Username:</strong> {{ page_user }}</p><br><br>
      <p><strong>Bio:</strong> {{ profile.bio }}</p><br><br>
      <p><strong>Twitter:</strong> {{ profile.twitter }}</p><br><br>
      <p><strong>Instagram:</strong> {{ profile.instagram }}</p><br><br>
      <p><strong>Facebook:</strong> {{ profile.facebook }}</p><br><br>
      <p>{{k}}</p>
      {% if user.id == profile.user.id %}
      <a href="{% url 'edit_user_profile' profile.id %}"><button class="button">Edit</button></a>
      {% endif %}
      
    
    
    </div>

{% endblock content %}

task_list.html

{% extends 'base/main.html' %}

{% block content %}

    <div class="header-bar">
        <div>
            <script language="javascript" type="text/javascript">
                var d = new Date();
                var day=new Array("Sunday","Monday","Tuesday",
                "Wednesday","Thursday","Friday","Saturday");
                var month=new Array("January","February","March","April","May","June",
                "July","August","September","October","November","December");
                document.write(day[d.getDay()]+" " +d.getDate()+ " " + month[d.getMonth()]
                + " " + d.getFullYear());
            </script>
            <h1>Hello, <a href="{% url 'edit_profile' %}">{{request.user|title}}</a></h1>
            <h3 style="margin:0">You have <i style="color:yellow">{{count}}</i> incomplete and <i style="color:yellow">{{k}}</i> complete tasks</h3>
        </div>

        {% if request.user.is_authenticated %}
            <ul class="ddropdownn">
                <li class="ddropdownn-top">
                    <a class="ddropdownn-top" href="#">Menu</a>
                    <ul class="ddropdownn-inside">
                        <li><a href="{% url 'top-users' %}">Top</a></li>
                        <li><a href="{% url 'about' %}">About</a></li>
                        <li><a href="{% url 'edit_profile' %}">Settings</a></li>
                        {% if user.profile.id %}
                        <li><a href="{% url 'user_profile' user.profile.id %}">Profile</a></li>
                        {% else %}
                        <li><a href="{% url 'create_user_profile'  %}">Profile</a></li>
                        {% endif %}
                        <li><a href="{% url 'logout' %}">Logout</a></li>
                        <li><a href="https://forms.yandex.ru/cloud/6170f0b40208c60589a01c66/">Support</a></li>
                    </ul>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2021-12-30
@bacon

Start by answering the question, where does k suddenly appear in user_profile.html?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question