我想将数据库信息呈现为HTML页面。我使用了从数据库传递动态数据的方法。但是,它不起作用。结果我看到一个空白页。
models.py
class Business(models.Model):
business_name = models.CharField(max_length=50)
business_services = models.CharField(max_length =50)
business_location = models.CharField(max_length=200)
business_description = models.TextField()
def __str__(self):
return self.business_name
views.py
def get_data(request):
business = Business.objects.all()
b = {'business': business}
return render(request, "test.html", b)
urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('', get_data),
]
test.html
{{ business.business_name }}
{{ business.services }}
答案 0 :(得分:1)
BootStrap.groovy
是类 new Module(title: "WebeC", description: "Web Engineering", semesterID: 1, grades: [4.0, 5.5, 3] ).save(flush: true)
的实例。因此,在test.html中,执行以下操作:
business