我收到的错误是
未定义全局名称“名称”...
为subjects = Course...
线。我想查询主题名称,以便可以在主题模板中使用它们
楷模
from django.db import models
from django.contrib.auth.models import User
class Course(models.Model):
name = models.CharField(max_length = 100)
stype = models.CharField(max_length = 100)
subject = models.CharField(max_length = 100)
location = models.CharField(max_length = 100)
class Teacher(models.Model):
username = models.ForeignKey(User,unique = True)
address = models.CharField(max_length = 200)
city = models.CharField(max_length = 50)
email_address = models.EmailField(max_length=75, unique = True)
class Student(models.Model):
username = models.ForeignKey(User,unique = True)
address = models.CharField(max_length = 200)
city = models.CharField(max_length = 50)
email_address = models.EmailField(max_length=75, unique = True)
class Attendance(models.Model):
course = models.ForeignKey(Course,unique = True)
student = models.ForeignKey(Student,unique = True)
teacher = models.ForeignKey(Teacher,unique = True)
date = models.DateField(unique = True)
status = models.BooleanField(unique = True)
created_at= models.DateTimeField(auto_now_add = True)
updated_at= models.DateTimeField(auto_now = True)
def subjects(request,username):
user = User.objects.get(username=username)
subjects = Course.objects.get(name = name)
variables = RequestContext(request,{
'username': username,
'subject' : subject
})
return render_to_response('subjects.html', variables)