0

我很难访问我在视图中返回的 rawCorpus 变量。每当我使用 alert: alert({{ rawCorpus }}) 对其进行测试时,它会弹出 undefined 作为消息。当我在视图中进行时,我真的需要一种方法来测试事物。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
4

0 回答 0