Just using forloop in template.
{% for r in result %}
{{ r.name }} {{ r.Type }}
{% endfor %}
Updated answer with view
your result is come from context.
Basically, django view render data to your own template. context_processors do that for you, and it's defined in settings.py (TEMPLATES - OPTIONS - context_processors).
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
str(ROOT_DIR.path('templates')),
],
# 'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
# you can add your own processors
'your_app.path.to.custom_processors',
],
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
},
},
]
Here's more detail information about context (official django docs)
It's why you can use request, user and other context data in your template.
If you want to use context in all templates, you can add your own context_processors. But in many times, you just want context only in particular template. (like your situation).
Then you can add your data to context, in your views.
If you're using Class Based View (I recommend using CBV), you can add by get_context_data(). like this.
class ProductView(ListView):
model = Product
template_name = 'best.html'
context_object_name = 'products'
def get_context_data(self, **kwargs):
context = super(ProductView, self).get_context_data(**kwargs)
context['test'] = 'test context data'
return context
You can add your own context data in existing context.
If you're using FBV, you can render template with your context. There're many ways to render (render, render_to_response, and so on.. You can check django docs for this. I guess you should use render cause render_to_response deprecated in django 2.0)
from django.shortcuts import render
def my_view(request):
# View code here...
context = {'test': 'test coooontext data' }
return render(request, 'myapp/index.html', context)
By passing your own context data in views, you can use this in template.
So if you want to pass only 'name' and 'type', you can pass data just you want to use, not all. It's more effective working in view then template. I hope it helps.