我想渲染一个模板。在模板中,我有一个名为“IsValid”的复选框,它的值来自数据库。我想阅读和编辑复选框的状态。编辑复选框后,我想将其值存储在数据库中。我应该如何写复选框?
<div class="form-group">
<label for="IsValid" class="control-label col-md-2">IsValid</label>
<div class="col-md-2">
<input type="checkbox" class="form-control" id="IsValid" name="IsValid" {{ checked="checked" if items[6]=1 else "" }} " >
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
代码中items[6]是通过视图函数传递的,它的值来自数据库,有两个值,0和1。
如何修改{{ checked="checked" if items[6]=1 else "" }}
?
因为这是错误的。
错误信息:jinja2.exceptions.TemplateSyntaxError:预期标记“打印语句结束”,得到“=”
我不知道你能不能听懂,因为我的英语很差。
# develop.yml
redis:
image: redis
command: redis-server --requirepass 123
ports:
- '6379:6379'
expose:
- "6379
Run Code Online (Sandbox Code Playgroud)
docker-compose -f develop.yml up redis
显示:
docker-compose -f develop.yml up redis
Starting django-blog_redis_1 ... done
Attaching to django-blog_redis_1
redis_1 | 1:C 16 Nov 2018 03:52:46.935 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 16 Nov 2018 03:52:46.935 # Redis version=5.0.1, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 16 Nov 2018 03:52:46.935 # Configuration loaded
redis_1 | 1:M 16 Nov 2018 03:52:46.935 # …
Run Code Online (Sandbox Code Playgroud)