Answer the question
In order to leave comments, you need to log in
How to display model variables in Django template?
Good day to all. I'll get straight to the point - I just can't display the variables from the model (which are already created in the admin panel) in the template. I have been sitting with this moment for 3 days, reviewed a bunch of guides, including the documentation, and for some reason nothing comes out.
view:
from django.shortcuts import render, get_object_or_404
from .models import Kitchen
def kuhni(request):
return render(request,'kuhni/kuhni.html')
def direct_kuhni(request):
return render(request,'kuhni/direct_kuhni.html')
def direct_name(request, id):
direct_product = get_object_or_404(Kitchen,
id=id)
return render(request,'kuhni/unique_kuhni.html', {'direct_product' : direct_product})
from django.db import models
class Kitchen(models.Model):
nameKitchen = models.CharField(max_length=30, name='Название')
top_facade = models.CharField(max_length=30, name='Верхние фасады', null=True, blank=True)
#Ниже остальное
def get_absolute_url(self):
return "/kuhni/direct_kuhni/%i/" % self.id
from django.urls import path
from . import views
urlpatterns = [
path('', views.kuhni, name='kuhni'),
path('direct_kuhni/', views.direct_kuhni,name='direct_kuhni'),
path('direct_kuhni/<int:id>/', views.direct_name),
]
{% extends 'base/base.html' %}
{% load static %}
{% block title %} {{ nameKitchen }} {% endblock %}
{% block content %}
<a>{{ nameKitchen }}</a>
<p>{{ top_facade }}</p>
{% endblock %}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question