访问Django view.py中的模型以输出文件

时间:2014-03-14 04:00:29

标签: python django csv

我想通过访问其中一个模型输出一个床文件并打印出整个列。

def ctb(request):
    # Create the HttpResponse object with the appropriate CSV header.
    response = HttpResponse(mimetype='text/bed')
    response['Content-Disposition'] = 'attachment; filename="somefilename.bed"'

    writer = csv.writer(response, delimiter='   ')
    for row in targetedgene:
        writer.writerow([row.1 , row.2])

    return response

错误说明:

  

异常值:语法无效

这是我的模特

class targetedgene(models.Model):
    cellline = models.CharField(max_length=150)
    targetedgenes = models.CharField(max_length=150)
    fullnamegene = models.CharField(max_length=150)
    chromlocation = models.CharField(max_length=10)
    startlocation = models.IntegerField(max_length=50)
    endlocation = models.IntegerField(max_length=50)
    regulated = models.CharField(max_length=10)


    def __unicode__(self):
        return self.targetedgenes+ "  .  " + self.fullnamegene + "  .  " + self.regulated 

我怎样才能写出每一行?如何在View.py中访问模型? 我可以在一个单独的文件中输出每一行吗?我希望将chromlocation,startlocation,endlocation和targetedgenes列合并到床文件中。

0 个答案:

没有答案