Python Django中的列表错误

Python Django中的列表错误,python,django,list,Python,Django,List,我正在使用Django并尝试将列表从视图传递到模板,我收到了这个错误 int()参数必须是字符串或数字,而不是“Taginfo” 遵循python视图代码。谢谢你的帮助 def datasource(request, datasource_id = 1): # if there is if Datasource.objects.filter(idestacao_meteo=datasource_id).count()>0 : result = Datasource.objects.

我正在使用Django并尝试将列表从视图传递到模板,我收到了这个错误
int()参数必须是字符串或数字,而不是“Taginfo”
遵循python视图代码。谢谢你的帮助

def datasource(request, datasource_id = 1):
# if there is
if Datasource.objects.filter(idestacao_meteo=datasource_id).count()>0 :
    result = Datasource.objects.get(idestacao_meteo=datasource_id)
    #if there is tags on this datasource        
    if Tag.objects.filter(datasource_idestacao_meteo = datasource_id).count>0:
        tags = Tag.objects.filter(datasource_idestacao_meteo = datasource_id)
        tagInfo = {'' : 0} 
        for tag in tags:
            tagInfo[tag.idtag] = Taginfo.objects.get(idtaginfo = tag.taginfo_idtaginfo1)
    else:
        tags = None         
    return render_to_response('Datasource/datasource.html',
        {'datasource' : result, 'tags' : tags}
    )
else:
    return render_to_response('Datasource/datasourceDoesNotExist.html',
        {'datasource_id' : datasource_id }
    )   
对不起,伙计们,这是这个类的模型代码:

class Datasource(models.Model):
idestacao_meteo = models.IntegerField(db_column='idESTACAO_METEO', primary_key=True, editable=False)  # Field name made lowercase.
nome_estacao = models.CharField(db_column='NOME_ESTACAO', max_length=45, blank=True)  # Field name made lowercase.
fabricante = models.CharField(db_column='FABRICANTE', max_length=45, blank=True)  # Field name made lowercase.
modelo = models.CharField(db_column='MODELO', max_length=45, blank=True)  # Field name made lowercase.
node_idnode = models.ForeignKey('Node', db_column='node_idNODE')  # Field name made lowercase.

class Meta:
    managed = False
    db_table = 'datasource'
和标签

class Tag(models.Model):
idtag = models.IntegerField(db_column='idTAG', primary_key=True, editable=False)  # Field name made lowercase.
desvio = models.FloatField(db_column='DESVIO', blank=True, null=True)  # Field name made lowercase.
tempo_max = models.IntegerField(db_column='TEMPO_MAX', blank=True, null=True)  # Field name made lowercase.
conv_rate = models.IntegerField(db_column='CONV_RATE', blank=True, null=True)  # Field name made lowercase.
taginfo_idtaginfo1 = models.ForeignKey('Taginfo', db_column='tagInfo_idtagInfo1')  # Field name made lowercase.
datasource_idestacao_meteo = models.ForeignKey(Datasource, db_column='datasource_idESTACAO_METEO')  # Field name made lowercase.

class Meta:
    managed = False
    db_table = 'tag'
我检查了一下名字,他们没有错。问题是我如何将列表传递给模板。 这是模板:

<html>
<body>
    <h2> Datasource ID: {{ datasource.idestacao_meteo }} </h2>
    <h2>Name: {{ datasource.nome_estacao }}</h2>
    <p>Manufacturer: {{ datasource.fabricante }}</p>
    <p>Model: {{ datasource.modelo }}</p>
    <hr size="4" width="100%"  noshade>
    {% if tags.count > 0 %}                     
        {% for tag in tags %}
            <div>
                <h3><a href = "http://127.0.0.1:8000/tags/get/{{ tag.idtag }}/">Tag {{ tag.idtag }}</a></h3>
            </div>
        {% endfor %}
    {% else %}

    {% endif %}
</body>

数据源ID:{{Datasource.idestacao_meteo}
名称:{{datasource.nome_estacao}
制造商:{{datasource.fabricante}

模型:{{datasource.modelo}


{%if tags.count>0%} {标记%中的标记的%s} {%endfor%} {%else%} {%endif%}


再次感谢。

idtaginfo=tag.taginfo\u idtaginfo1

可能需要


idtainfo\u id=tag.taginfo\u idtaginfo1

tag.idtag是哪种类型的??它是整数、字符串还是标记信息?“tags”不在“return render_to_response('Datasource/Datasource.html',{'Datasource':result,'tags':tags}”的范围内欢迎来到StackOverflow。这个问题在满足这里的问题指导线方面充其量只是一个边缘问题。幸运的是,慷慨的回答者不辞辛劳地解决了这个问题。尽管如此,如果你不解决它,它可能会被关闭。至少,你需要发布错误的完整回溯。理想情况下,你应该尝试一下我指出这一点是为了让你们下次意识到:这个问题目前正在审查中,有待结束,标记为不符合指导原则。