Вот HTML:
Код: Выделить всё
List of Plants
Plants
[list]
{% for plant in plants %}
[*]{{ plant.name }}
[*]Scientific Name: {{ plant.scientific_name }}
[*]Description: {{ plant.plant_description }}
[*]Price: ${{ plant.price }}
[*]Water Needs: {{ plant.water }}
[*]Light Needs: {{ plant.light }}
[*]Humidity Needs: {{ plant.humidity }}
[*]Temperature Needs: {{ plant.temp }}
[*]Toxicity: {{ plant.toxic }}
[*]Fun Fact: {{ plant.fun_fact }}
{% endfor %}
[/list]
Код: Выделить всё
from django.shortcuts import render
from .models import Plant # Make sure to import your model
def index(request):
plants = Plant.objects.all()
return render(request, 'index.html', {'plants': plants})
Код: Выделить всё
from django.db import models
class Plant(models.Model):
objects = models.Manager()
plant_id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)
scientific_name = models.CharField(max_length=200)
plant_description = models.CharField(max_length=500)
price = models.DecimalField(max_digits=10, decimal_places=2)
image_name = models.CharField(max_length=256, blank=True, null=True)
water = models.CharField(max_length=500)
light = models.CharField(max_length=999)
humidity = models.CharField(max_length=999)
temp = models.CharField(max_length=999)
toxic = models.CharField(max_length=999)
fun_fact = models.CharField(max_length=999)
soil_id = models.IntegerField(null=True)
def __str__(self):
return self.name
class Meta:
db_table = 'plants' # Specify the database table name
Подробнее здесь: https://stackoverflow.com/questions/786 ... ango-error