OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Django partial template rendering not updating the page, but showing up in console

  • Thread starter Thread starter NAs
  • Start date Start date
N

NAs

Guest
I have a django-based webpage I am working on (Django version 5.0). This page allows for clicking on a item in a table and the intention is to display subitems related to the item, without redrawing the whole page. Though my subtemplate is being seen by Django and acted upon, instead of updating the portion of the html in the page, the resulting html is being dumped in the console. Here are some code snippets:

main.html contains, among many other things, the following positioned where I want the content:

Code:
{% include '_subtemplate.html' %}

_subtemplate contains:

Code:
{% for subitem in subitems %}
<tr>
  <td><a onclick='mySubItemClick("{{ subitem.date }}")'>{{ subitem.date }}</a></td>
  <td>{{ subitem.my_note }}</td>
</tr>
{% endfor %}

views.py contains:

Code:
def get_my_subitems(requests, site_id):
    subitems = # code to get a list of objects
    return render(request, '_subtemplate.html', { 'subitems': subitems })

urls.py contains a correct path entry in urlpatterns:

Code:
path('myitems/mysubitems/<int:site_id>/', views.get_my_subitems, name='get_my_subitems'),

I have a javascript file that contains a method which makes a working ajax call where 'path: /myitems/mysubitems/' + obj.site_id

Instead of seeing my list of subitem content reload in the html page, when I open the browser console, I am seeing the correctly templated html there and not in the page.

Code:
<tr>
  <td><a onclick='mySubItemClick("June 13, 2024")'>June 13, 2024</a></td>
  <td>misc notes...</td>
</tr>

There are no errors in the javascript console or the django server. Clearly, I am getting my data and formatting it properly, but include seems like it is dropping the ball at the end.
<p>I have a django-based webpage I am working on (Django version 5.0). This page allows for clicking on a item in a table and the intention is to display subitems related to the item, without redrawing the whole page. Though my subtemplate is being seen by Django and acted upon, instead of updating the portion of the html in the page, the resulting html is being dumped in the console. Here are some code snippets:</p>
<p>main.html contains, among many other things, the following positioned where I want the content:</p>
<pre><code>{% include '_subtemplate.html' %}
</code></pre>
<p>_subtemplate contains:</p>
<pre><code>{% for subitem in subitems %}
<tr>
<td><a onclick='mySubItemClick("{{ subitem.date }}")'>{{ subitem.date }}</a></td>
<td>{{ subitem.my_note }}</td>
</tr>
{% endfor %}
</code></pre>
<p>views.py contains:</p>
<pre><code>def get_my_subitems(requests, site_id):
subitems = # code to get a list of objects
return render(request, '_subtemplate.html', { 'subitems': subitems })
</code></pre>
<p>urls.py contains a correct path entry in urlpatterns:</p>
<pre><code>path('myitems/mysubitems/<int:site_id>/', views.get_my_subitems, name='get_my_subitems'),
</code></pre>
<p>I have a javascript file that contains a method which makes a working ajax call where 'path: /myitems/mysubitems/' + obj.site_id</p>
<p>Instead of seeing my list of subitem content reload in the html page, <strong>when I open the browser console, I am seeing the correctly templated html there and not in the page.</strong></p>
<pre><code><tr>
<td><a onclick='mySubItemClick("June 13, 2024")'>June 13, 2024</a></td>
<td>misc notes...</td>
</tr>
</code></pre>
<p>There are no errors in the javascript console or the django server. Clearly, I am getting my data and formatting it properly, but <code>include</code> seems like it is dropping the ball at the end.</p>
Continue reading...
 

Latest posts

I
Replies
0
Views
1
Ihsan Sadat
I
Top