Django - 显示CommaSeparatedIntegerField的值

时间:2017-09-03 15:13:33

标签: python django django-models

如何在CommaSeparatedIntegerField的HTML值中显示?

以下是一些代码:

models.py

class Test(models.Model):
    oceny = models.CommaSeparatedIntegerField(max_length=150)

    def __str__(self):
        return "Test"

views.py

from django.shortcuts import render, HttpResponse
from .models import Test


def test(request):
    mymodel = Test
    return render(request, 'oceny/main.html')

1 个答案:

答案 0 :(得分:1)

这只是一个child of CharField。所以,您可以像这样显示它:

{{ oceny }}

但首先,请确保将其发送到您的视图中:

def test(request):
    my_object = Test.objects.get(pk=1)
    return render(request, 'oceny/main.html', {'oceny': my_object.oceny})