1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
{% load staticfiles %}
<html lang="en">
<head>
<meta charset="UTF-8">
<title>讲师信息</title>
<style>
.container {
width: 960px;
margin: 0 auto;
}
.basic {
width: 60%;
float: left;
}
.potrait {
width: 40%;
float: left;
text-align: right;
}
hr {
clear: both;
}
.button {
display: inline-block;
width: 80px;
height: 30px;
background-color: red;
color: white;
font: 16px/30px Arial;
text-decoration: none;
text-align: center;
}
</style>
</head>
<body>
<!-- 页面的显示逻辑 -->
{% for x in teachers_list %}
<div class="container">
<div class="basic">
<h1>{{ x.name }}老师 - {{ x.subject.name }}</h1>
<p><strong>讲师简介</strong></p>
<p>{{ x.intro }}</p>
<p><strong>教学理念</strong></p>
<p>{{ x.motto }}</p>
<a href="/good/{{ x.no }}" class="button">好评({{ x.gcount }})</a>
<a href="/bad/{{ x.no }}" class="button">差评({{ x.bcount }})</a>
</div>
<div class="potrait">
{% if x.photo %}
<img src="{% static x.photo %}">
{% endif %}
</div>
<hr>
</div>
{% endfor %}
<script src="{% static 'js/jquery.min.js' %}"></script>
<script>
$(function() {
$('.basic .button').on('click', function(evt) {
evt.preventDefault();
var $a = $(evt.target);
var url = $a.attr('href');
$.ajax({
'url': url,
'type': 'get',
'data': {},
'dataType': 'json',
'success': function(json) {
if (json.code == 200) {
$a.text(json.result);
} else if (json.code == 403) {
alert(json.result);
}
},
'error': function() {}
});
});
});
</script>
</body>
</html>