First time building a django site and keep running into this error with my index.html file for one of the sites that’ll hold a list of plants. The error I keep getting is: routers doesn’t look like a module path–. Any tips?
Here’s the html:
<!-- plants/templates/index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>List of Plants</title>
</head>
<body>
<h1>Plants</h1>
<ul>
{% for plant in plants %}
<li>{{ plant.name }}</li>
<li>Scientific Name: {{ plant.scientific_name }}</li>
<li>Description: {{ plant.plant_description }}</li>
<li>Price: ${{ plant.price }}</li>
<li>Water Needs: {{ plant.water }}</li>
<li>Light Needs: {{ plant.light }}</li>
<li>Humidity Needs: {{ plant.humidity }}</li>
<li>Temperature Needs: {{ plant.temp }}</li>
<li>Toxicity: {{ plant.toxic }}</li>
<li>Fun Fact: {{ plant.fun_fact }}</li>
<br>
{% endfor %}
</ul>
</body>
</html>
Here’s the view:
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})
and here’s my model:
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
Tried everything, but am at a loss.
New contributor
Jack Nichols is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.