一.上节回顾
1 路由匹配从上往下匹配,一旦匹配成功,就不再往下匹配
re_path(r'^$',book.index),
2 反向解析
-用在模板中
-用在视图函数中
3 图片列表之作者显示(for循环中套if),for+empty的使用
<td>
{
% for author in book.authors.all %}
{
% if forloop.last %}
{
{
author.name }}
{
% else %}
{
{
author.name }} -- |--
{
% endif %}
{
% empty %}
未知作者
{
% endfor %}
</td>
4 图片编辑的连接
-<td><a href="/book_update/{
{book.id}}/">编辑</a></td>
-<td><a href="{% url 'bookupdate' book.id %}/">编辑</a></td>
-<td><a href="/book_update/?pk={
{
book.id}}>编辑</a></td>
5 模板变量可以给js使用
python中
ss='lqz'
<script>
var a='{
{sss}}'
var a=lqz
</script>
6 修改,出版社跟图书真正的出版社对应
<select class="form-control" name="publish"
>
{
% for publish in publishs %}
{
% if book.publish.id == publish.id %}
<option value="{
{publish.id}}" selected>{
{
publish.name}}</option>
{
% else %}
<option value="{
{publish.id}}" >{
{
publish.name}}</option>
{
% endif %}
{
% endfor %}
</select>
7 修改,作者
<select multiple class="form-control" name="authors">
{
% with book.authors.all as xxx %}
{
% for author in authors %}
{
% if author in xxx %}
<option value="{
{ author.id }}" selected>{
{
author.name }}</option