menu

arrow_back Why isn't the Django template rendered?

by
1 vote
In general, you need to output k in user_profile. In task_list it is displayed successfully, but in user_profile it is not. 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>

1 Answer

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

6 Comments

Vladislava Ok, wait for comments from normal people, I will read "with my eyes narrow Turkmen.
Dr. Bacon I told you, narcissist.
Vladislava Oh how bad it is, it's not a show, that's why I sent you to teach. It's just the output of a variable that wasn't transferred there. You have to pass in a view that explicitly interacts with this pattern or in a context processor. Curtain.
Dr. Bacon I'm sorry it's not going well for you. According to your logic, he shouldn't be able to output it. But it does. Check out
Vladislava It's hard to guess what's in the unspecified code, the crystal ball froze from the cold. And especially with the stubborn