from django.shortcuts import render
from django.http import HttpResponse
def index(request):
all_employee = employee.objects.all()
html = ''
for employee in all_employee:
url = 'mainpage/' + str(employee.id) + '/'
html += '<a href ="' + url + '">' + url + '</a><br>'
return HttpResponse(html)
def details(request, id):
return HttpResponse("<h2>This is the details for" + str(id) + " </h2>")
第all_employee = employee.objects.all()
行给出了错误,当我在shell中使用此命令时,给出了该错误:
[<employee: employee object>, <employee: employee object>, <employee: employee object>]
代替每行数据。
答案 0 :(得分:0)
您违反了Django的MVT模式,但现在暂时跳过。
Employee
模型类(如果没有其他原因,首字母大写)。return HttpResponse(html)
完全相同的水平上使用for语句。