-1

エラーが発生しています

グローバル名 'name' が定義されていません...

ラインのために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)
4

2 に答える 2

1

subjects = Course.objects.get(name = name)name定義されていません。

関数の引数でnamelikeを渡すことができます。username

def subjects(request,username, name):

または、次のような他の文字列の代わりにname

subjects = Course.objects.get(name ="course_name")

于 2012-06-04T11:38:37.537 に答える
0

あなたはusername入ってdef subjects(request,username):いますが..

subjects  = Course.objects.get(name = name)   ### name is not defined here...you have to get it from parameter just like username.
于 2012-06-04T11:31:58.663 に答える