我很难在django视图中返回变量。

时间:2013-08-28 00:12:59

标签: javascript python django

我很难访问我在视图中返回的rawCorpus变量。当我使用alert:alert({{rawCorpus}})对其进行测试时,会弹出未定义的消息。我真的需要一种方法来测试事物,因为我在视图中进行测试。 IE:我个人变量的打印方法,不需要经过返回过程。

views.py

def homesite(request):
rawCorpus = ""
corpusitems = CorpusItem.objects.order_by('name')
if (request.method == 'POST') and "namefortextinput" in request.POST:
    f = CorpusItemForm(request.POST)
    if f.is_valid():
        new_corpusitem = f.save()       

elif (request.method == 'POST') and 'selectedCorpusChoiceTokenizeWords' in request.POST:
    g = CorpusChoiceForm(request.POST)
    if g.is_valid():
        new_corpuschoice = g.save()
        rawCorpus = g.__getitem__(name)


Models.py

class CorpusItem(models.Model):
name = models.CharField(max_length=100)
content = models.CharField(max_length=9000)


   def __unicode__(self):
       return self.name

class CorpusItemForm(ModelForm):
    class Meta:
        model = CorpusItem

   def __str__():
    return name 
    from django import forms

class CorpusChoice(models.Model):
    name = models.CharField(max_length=100)

class CorpusChoiceForm(ModelForm):
    class Meta:
        model = CorpusChoice

0 个答案:

没有答案