这个问题是关于在选择器的选择中正确呈现 html。这是我的代码:
模型.py
from django.db import models
class Test(models.Model):
area = models.FloatField(choices=((0, '0 mm²'), (0.5, '0.5 mm²')), default=0)
视图.py
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.forms import ModelForm
from models import Test
class TestForm(ModelForm):
class Meta:
model = Test
def test(request):
form = TestForm()
return render_to_response('test.html', RequestContext(request, {'form': form}))
测试.html
{{ form.area }}
{{ form.area|safe }}
{% autoescape off %}{{ form.area }}{% endautoescape %}
以上三个选项都不能成功地将选择器选项正确显示为0 mm²而不是0 mm²
. 如何解决?