Evans Olang
Evans Olang

Reputation: 1

Django models not rendering when I use boiler plate

There is no error when i try to render. it works fine when i don't use django dashboard boiler plate. I tested the query set on shell and its working. the data can be seen on admin. its just not rendering on the html template. not sure if the url setup impacts it.

I have tried changing how to render on the template, still not working. any one with an idea how to correct it?

urls

from django.urls import path, include, re_path
from . import views

urlpatterns = [

    # The home page
    path('', views.index, name='home'),
  
    # Matches any html file
    re_path(r'^.*\.*', views.pages, name='pages'),

]

Views
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, get_object_or_404, redirect
from django.template import loader
from django.http import HttpResponse
from django import template
from stockmgmt import views
from .models import *
from .forms import *


@login_required(login_url="/login/")
def index(request):

    context = {}
    context['segment'] = 'index'

    html_template = loader.get_template('index.html')
    return HttpResponse(html_template.render(context, request))


def list_tables(request):
    title = 'List of Items'
    # form = StockSearchForm(request.POST or None)
    queryset = Stock.objects.all()
    context = {
        "title": title,
        "queryset": queryset,
        "form": form,
    }
    return render(request, "list_tables.html", context)



list_tables.html
 {% for instance in queryset %}
      
                        <tr>
                          <td><input type="checkbox" class="checkthis" /></td>
                          <td>{{forloop.counter}}</td>
                          <td>{{instance.category}}</td>
                          <td>{{instance.item_name}}</td>
                          <td>{{instance.use}}</td>
                          <td>{{instance.size}}</td>
                          <td>{{instance.color}}</td>
                          <td>{{instance.packaging}}</td>
                        
                          <!-- ====================================================================================== -->
                          <!-- # 28. 4. Make a template tag in the list_items.html condition with a div rapping the quantity field that will apply a style to the field when the reorder level is equal to or less than the quantity -->
                          <!-- <td><a href="{% url 'stock_detail' instance.id %}">{{instance.quantity}}</a></td> -->
                          <td>
                            {% if instance.quantity <= instance.reorder_level %}
                            <div style="background-color: orange;">
                              <a href="{% url 'stock_detail' instance.id %}">{{instance.quantity}}</div>
                            {% else %}
                              <a href="{% url 'stock_detail' instance.id %}">{{instance.quantity}}</div>
                            {% endif %}
                          </td>
                      
                          <!-- Step 28.5 - Add a column for reorder level and make is clickable to update the reorder level -->
                          <td><a href="{% url 'reorder_level' instance.id %}">{{instance.reorder_level}}</a></td> 
                          <!-- ====================================================================================== -->
                          <td>{{instance.receive_by}}</td>
                          <td>{{instance.issue_by}}</td>
                          <td>{{instance.issue_to}}</td>
                          <td>{{instance.create_by}}</td>
                          <td>{{instance.e_date}}</td>
                          <td>{{instance.timestamp}}</td>
                        
                          <td>{{instance.last_updated}}</td>
                          <td><a href="{% url 'update_items' instance.id %}" class="btn btn-success">Update</a>
                          <td><a href="{% url 'delete_items' instance.id %}" class="btn btn-danger">Delete</a>
                          </td>
                        </tr>
                       {% endfor %}

Upvotes: 0

Views: 130

Answers (1)

Shreyash mishra
Shreyash mishra

Reputation: 790

the issue is in your urls.py you did not define your list_tabels in url

path('List_tabels/',view.list_tables,name='list_tabel')

Upvotes: 0

Related Questions