列表詳情頁的開發(fā)
標(biāo)簽: django
django template繼承
模板繼承
base.html
{% block title %}<head> 你好 </head>{% endblock %}
extend.html
{% extends 'base.html' %}
文件上傳位置
setting
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
base.html
<!DOCTYPE html>
<html>
{% load staticfiles %}
<head>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" >
<title>{% block title %}課程機(jī)構(gòu)列表 - 慕學(xué)在線網(wǎng){% endblock %}</title>
<link rel="stylesheet" type="text/css" href="/static/css/reset.css">
<link rel="stylesheet" type="text/css" href="/static/css/animate.css">
<link rel="stylesheet" type="text/css" href="/static/css/style.css">
<script src="/static/js/jquery.min.js" type="text/javascript"></script>
<script src="/static/js/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>
</head>
<body>
<section class="headerwrap ">
<header>
<div class=" header">
<div class="top">
<div class="wp">
<div class="fl"><p>服務(wù)電話:<b>33333333</b></p></div>
<!--登錄后跳轉(zhuǎn)-->
<a style="color:white" class="fr registerbtn" href="register.html">注冊</a>
<a style="color:white" class="fr loginbtn" href="login.html">登錄</a>
</div>
</div>
<div class="middle">
<div class="wp">
<a href="index.html"><img class="fl" src="/static/images/logo.jpg"/></a>
<div class="searchbox fr">
<div class="selectContainer fl">
<span class="selectOption" id="jsSelectOption" data-value="course">
公開課
</span>
<ul class="selectMenu" id="jsSelectMenu">
<li data-value="course">公開課</li>
<li data-value="org">課程機(jī)構(gòu)</li>
<li data-value="teacher">授課老師</li>
</ul>
</div>
<input id="search_keywords" class="fl" type="text" value="" placeholder="請輸入搜索內(nèi)容"/>
<img class="search_btn fr" id="jsSearchBtn" src="/static/images/search_btn.png"/>
</div>
</div>
</div>
<nav>
<div class="nav">
<div class="wp">
<ul>
<li ><a href="index.html">首頁</a></li>
<li >
<a href="course-list.html">
公開課<img class="hot" src="/static/images/nav_hot.png">
</a>
</li>
<li >
<a href="teachers-list.html">授課教師</a>
</li>
<li class="active" ><a href="org-list.html">授課機(jī)構(gòu)</a></li>
</ul>
</div>
</div>
</nav>
</div>
</header>
</section>
<!--crumbs start-->
{% block custom_bread %}
<section>
<div class="wp">
<ul class="crumbs">
<li><a href="index.html">首頁</a>></li>
</ul>
</div>
</section>
{% endblock %}
{% block custom_content %}
{% endblock %}
<footer>
<div class="footer">
<div class="wp">
<ul class="cont">
<li class="logo"><a href=""><img src="/static/images/footlogo.png"/></a></li>
<li class="code"><img src="/static/images/code.jpg"/><p class="center">掃描關(guān)注微信</p></li>
<li class="third"><img class="fl" src="/static/images/tell.png"/><p class="tell">33333333</p><p class="time">周一至周日 9:00-18:00</p></li>
</ul>
</div>
<p class="line"></p>
<div class="wp clear">
<span class="fl">? 2016 www.projectsedu.com 慕學(xué)在線-在線學(xué)習(xí)交流平臺 保留所有權(quán)利</span>
<span class="fr">copyright ? 2016 ICP備案證書號:蜀ICP備xxxxx號-1</span>
</div>
</div>
</footer>
<section>
<ul class="sidebar">
<li class="qq">
<a target="_blank" ></a>
</li>
<li class="totop"></li>
</ul>
</section>
<script src="/static/js/selectUi.js" type='text/javascript'></script>
<script src="/static/js/deco-common.js" type='text/javascript'></script>
<script type="text/javascript" src="/static/js/plugins/laydate/laydate.js"></script>
<script src="/static/js/plugins/layer/layer.js"></script>
<script src="/static/js/plugins/queryCity/js/public.js" type="text/javascript"></script>
<script src="/static/js/unslider.js" type="text/javascript"></script>
<script src="/static/js/plugins/jquery.scrollLoading.js" type="text/javascript"></script>
<script src="/static/js/deco-common.js" type="text/javascript"></script>
<script>
$(function(){
$('#jsStayBtn').on('click', function(){
$.ajax({
cache: false,
type: "POST",
url:"/org/add_ask/",
data:$('#jsStayForm').serialize(),
async: true,
success: function(data) {
if(data.status == 'success'){
$('#jsStayForm')[0].reset();
alert("提交成功")
}else if(data.status == 'fail'){
$('#jsCompanyTips').html(data.msg)
}
},
});
});
})
</script>
</body>
</html>
org_list.html
{% extends 'common/base.html' %}
{% load staticfiles %}
{% block custom_bread %}
<section>
<div class="wp">
<ul class="crumbs">
<li><a href="index.html">首頁</a>></li>
<li>課程機(jī)構(gòu)</li>
</ul>
</div>
</section>
{% endblock %}
{% block custom_content %}
<section>
<div class="wp butler_list_box list">
<div class='left'>
<div class="listoptions">
<ul>
<li>
<h2>機(jī)構(gòu)類別</h2>
<div class="cont">
<a href="?city="><span class="active2">全部</span></a>
<a href="?ct=pxjg&city="><span class="">培訓(xùn)機(jī)構(gòu)</span></a>
<a href="?ct=gx&city="><span class="">高校</span></a>
<a href="?ct=gr&city="><span class="">個(gè)人</span></a>
</div>
</li>
<li>
<h2>所在地區(qū)</h2>
<div class="more">更多</div>
<div class="cont">
<a href="?ct="><span class="active2">全部</span></a>
{% for city in all_citys %}
<a href="?city=1&ct="><span class="">{{ city.name }}</span></a>
{% endfor %}
</div>
</li>
</ul>
</div>
<div class="all">共<span class="key">{{ org_nums }}</span>家</div>
<div class="butler_list company list">
<div class="layout">
<div class="head">
<ul class="tab_header">
<li class="active"><a href="?ct=&city=">全部</a> </li>
<li class=""><a href="?sort=students&ct=&city=">學(xué)習(xí)人數(shù) ↓</a></li>
<li class=""><a href="?sort=courses&ct=&city=">課程數(shù) ↓</a></li>
</ul>
</div>
{% for course_org in all_courses %}
<dl class="des difdes">
<dt>
<a href="org-detail-homepage.html">
<img width="200" height="120" class="scrollLoading" data-url="{{ MEDIA_URL }}{{ course_org.image }}"/>
</a>
</dt>
<dd>
<div class="clearfix">
<a href="org-detail-homepage.html">
<h1>{{ course_org.name }}</h1>
<div class="pic fl">
<img src="/static/images/authentication.png"/>
<img src="/static/images/gold.png"/>
</div>
</a>
</div>
<ul class="cont">
<li class="first"><p class="pic9">課程數(shù):<span>1</span></p><p class="c7">學(xué)習(xí)人數(shù):<span>1000</span></p></li>
<li class="c8" style="padding-left:18px;">{{ course_org.address }}</li>
<li class="pic10" style="padding-left:18px;">經(jīng)典課程:
<a href="/diary/19/">c語言基礎(chǔ)入門</a>
<a href="/diary/16/">數(shù)據(jù)庫基礎(chǔ)</a>
</li>
</ul>
</dd>
<div class="buy start_groupbuy jsShowPerfect2" data-id="22"><br/>聯(lián)系<br/>服務(wù)</div>
</dl>
{% endfor %}
</div>
<div class="pageturn">
<ul class="pagelist">
<li class="active"><a href="?page=1">1</a></li>
<li><a href="?page=2" class="page">2</a></li>
<li><a href="?page=3" class="page">3</a></li>
<li class="long"><a href="?page=2">下一頁</a></li>
</ul>
</div>
</div>
</div>
<div class="right companyright">
<div class="head">我要學(xué)習(xí)</div>
<form class="rightform" id="jsStayForm">
<div>
<img src="/static/images/rightform1.png"/>
<input type="text" name="name" id="companyName" placeholder="名字" maxlength="25" />
</div>
<div>
<img src="/static/images/rightform2.png"/>
<input type="text" name="mobile" id="companyMobile" placeholder="聯(lián)系電話"/>
</div>
<div>
<img src="/static/images/rightform3.png"/>
<input type="text" name="course_name" id="companyAddress" placeholder="課程名" maxlength="50" />
</div>
<p class="error company-tips" id="jsCompanyTips"></p>
<input class="btn" type="text" id="jsStayBtn" value="立即咨詢 >" />
<input type='hidden' name='csrfmiddlewaretoken' value='5I2SlleZJOMUX9QbwYLUIAOshdrdpRcy' />
</form>
</div>
<div class="right companyrank layout">
<div class="head">授課機(jī)構(gòu)排名</div>
<dl class="des">
<dt class="num fl">1</dt>
<dd>
<a href="/company/2/"><h1>慕課網(wǎng)</h1></a>
<p>北京市</p>
</dd>
</dl>
<dl class="des">
<dt class="num fl">2</dt>
<dd>
<a href="/company/2/"><h1>慕課網(wǎng)2</h1></a>
<p>深圳市</p>
</dd>
</dl>
<dl class="des">
<dt class="num fl">3</dt>
<dd>
<a href="/company/2/"><h1>北京大學(xué)</h1></a>
<p>北京市</p>
</dd>
</dl>
</div>
</div>
</section>
{% endblock %}
結(jié)構(gòu)列表頁動(dòng)態(tài)數(shù)據(jù)展示
class OrgListView(View):
"""
機(jī)構(gòu)列表顯示
"""
def get(self, request):
all_courses = CourseOrg.objects.all()
org_nums = all_courses.count()
all_citys = CityDict.objects.all()
return render(request, 'org_list.html', {
'all_courses': all_courses,
'all_citys': all_citys,
'org_nums': org_nums
})
圖片訪問路徑url設(shè)置
url(r'^org_list/$', OrgListView.as_view(), name='org_list'),
# medias watch
url(r'^media/(?P<path>.*)/$', serve, {'document_root': MEDIA_ROOT})
列表分頁功能實(shí)現(xiàn)
基于開源的django-pure-pagination,對于數(shù)據(jù)進(jìn)行分頁信息展示想罕。具體操作github說明齊全。 地址
添加app注冊仿村,修改返回結(jié)果陋葡,修改前端界面
apps
'pure_pagination'
from pure_pagination import Paginator, EmptyPage, PageNotAnInteger
class OrgListView(View):
"""
機(jī)構(gòu)列表顯示
"""
def get(self, request):
all_courses = CourseOrg.objects.all()
# 分頁功能展示
try:
page = request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
p = Paginator(all_courses, 5, request=request)
all_orgs = p.page(page)
org_nums = all_courses.count()
all_citys = CityDict.objects.all()
return render(request, 'org_list.html', {
'all_courses': all_orgs,
'all_citys': all_citys,
'org_nums': org_nums
})
<div class="pageturn">
<ul class="pagelist">
{% if all_courses.has_previous %}
<li class="long"><a href="?{{ all_courses.previous_page_number.querystring }}">上一頁</a></li>
{% endif %}
{% for page in all_courses.pages %}
{% if page %}
{% ifequal page all_courses.number %}
<li class="active"><a href="">{{ page }}</a></li>
{% else %}
<li><a href="?{{ page.querystring }}" class="page">{{ page }}</a></li>
{% endifequal %}
{% else %}
<li class="none"><a href="">...</a></li>
{% endif %}
{% endfor %}
{% if all_courses.has_next %}
<li class="long"><a href="?{{ all_courses.next_page_number.querystring }}">下一頁</a></li>
{% endif %}
</ul>
</div>
刪選條件排序
異步頁面刷新方式谭企,通過連接傳遞參數(shù)的方式呵晚,不同條件之間需要通過關(guān)聯(lián)篩選。
{% extends 'common/base.html' %}
{% load staticfiles %}
{% block custom_bread %}
<section>
<div class="wp">
<ul class="crumbs">
<li><a href="index.html">首頁</a>></li>
<li>課程機(jī)構(gòu)</li>
</ul>
</div>
</section>
{% endblock %}
{% block custom_content %}
<section>
<div class="wp butler_list_box list">
<div class='left'>
<div class="listoptions">
<ul>
<li>
<h2>機(jī)構(gòu)類別</h2>
<div class="cont">
<a href="?city_id={{ city_id }}"><span class="{% ifequal category '' %}active2{% endifequal %}">全部</span></a>
<a href="?ct=pxjg&city_id={{ city_id }}"><span class="{% ifequal category 'pxjg' %}active2{% endifequal %}">培訓(xùn)機(jī)構(gòu)</span></a>
<a href="?ct=gx&city_id={{ city_id }}"><span class="{% ifequal category 'gx' %}active2{% endifequal %}">高校</span></a>
<a href="?ct=gr&city_id={{ city_id }}"><span class="{% ifequal category 'gr' %}active2{% endifequal %}">個(gè)人</span></a>
</div>
</li>
<li>
<h2>所在地區(qū)</h2>
<div class="more">更多</div>
<div class="cont">
<a href="?ct={{ category }}"><span class="{% ifequal city_id '' %}active2{% endifequal %}">全部</span></a>
{% for city in all_citys %}
<a href="?city_id={{ city.id }}&ct={{ category }}"><span class="{% ifequal city_id city.id|stringformat:'i' %} active2 {% endifequal %}">{{ city.name }}</span></a>
{% endfor %}
</div>
</li>
</ul>
</div>
<div class="all">共<span class="key">{{ org_nums }}</span>家</div>
<div class="butler_list company list">
<div class="layout">
<div class="head">
<ul class="tab_header">
<li class="{% ifequal sort '' %}active{% endifequal %}"><a href="?ct={{ category }}&city_id={{ city_id }}">全部</a> </li>
<li class="{% ifequal sort 'students' %}active{% endifequal %}"><a href="?sort=students&ct={{ category }}&city_id={{ city_id }}">學(xué)習(xí)人數(shù) ↓</a></li>
<li class="{% ifequal sort 'courses' %}active{% endifequal %}"><a href="?sort=courses&ct={{ category }}&city_id={{ city_id }}">課程數(shù) ↓</a></li>
</ul>
</div>
{% for course_org in all_courses.object_list %}
<dl class="des difdes">
<dt>
<a href="org-detail-homepage.html">
<img width="200" height="120" class="scrollLoading" data-url="{{ MEDIA_URL }}{{ course_org.image }}"/>
</a>
</dt>
<dd>
<div class="clearfix">
<a href="org-detail-homepage.html">
<h1>{{ course_org.name }}</h1>
<div class="pic fl">
<img src="/static/images/authentication.png"/>
<img src="/static/images/gold.png"/>
</div>
</a>
</div>
<ul class="cont">
<li class="first"><p class="pic9">課程數(shù):<span>1</span></p><p class="c7">學(xué)習(xí)人數(shù):<span>1000</span></p></li>
<li class="c8" style="padding-left:18px;">{{ course_org.address }}</li>
<li class="pic10" style="padding-left:18px;">經(jīng)典課程:
<a href="/diary/19/">c語言基礎(chǔ)入門</a>
<a href="/diary/16/">數(shù)據(jù)庫基礎(chǔ)</a>
</li>
</ul>
</dd>
<div class="buy start_groupbuy jsShowPerfect2" data-id="22"><br/>聯(lián)系<br/>服務(wù)</div>
</dl>
{% endfor %}
</div>
<div class="pageturn">
<ul class="pagelist">
{% if all_courses.has_previous %}
<li class="long"><a href="?{{ all_courses.previous_page_number.querystring }}">上一頁</a></li>
{% endif %}
{% for page in all_courses.pages %}
{% if page %}
{% ifequal page all_courses.number %}
<li class="active"><a href="">{{ page }}</a></li>
{% else %}
<li><a href="?{{ page.querystring }}" class="page">{{ page }}</a></li>
{% endifequal %}
{% else %}
<li class="none"><a href="">...</a></li>
{% endif %}
{% endfor %}
{% if all_courses.has_next %}
<li class="long"><a href="?{{ all_courses.next_page_number.querystring }}">下一頁</a></li>
{% endif %}
</ul>
</div>
</div>
</div>
<div class="right companyright">
<div class="head">我要學(xué)習(xí)</div>
<form class="rightform" id="jsStayForm">
<div>
<img src="/static/images/rightform1.png"/>
<input type="text" name="name" id="companyName" placeholder="名字" maxlength="25" />
</div>
<div>
<img src="/static/images/rightform2.png"/>
<input type="text" name="mobile" id="companyMobile" placeholder="聯(lián)系電話"/>
</div>
<div>
<img src="/static/images/rightform3.png"/>
<input type="text" name="course_name" id="companyAddress" placeholder="課程名" maxlength="50" />
</div>
<p class="error company-tips" id="jsCompanyTips"></p>
<input class="btn" type="text" id="jsStayBtn" value="立即咨詢 >" />
<input type='hidden' name='csrfmiddlewaretoken' value='5I2SlleZJOMUX9QbwYLUIAOshdrdpRcy' />
</form>
</div>
<div class="right companyrank layout">
<div class="head">授課機(jī)構(gòu)排名</div>
{% for org in hot_orgs %}
<dl class="des">
<dt class="num fl">{{ forloop.counter }}</dt>
<dd>
<a href="/company/2/"><h1>{{ org.name }}</h1></a>
<p>{{ org.address }}</p>
</dd>
</dl>
{% endfor %}
</div>
</div>
</section>
{% endblock %}
class OrgListView(View):
"""
機(jī)構(gòu)列表顯示
"""
def get(self, request):
all_courses = CourseOrg.objects.all()
# 排序方式篩選
# 右側(cè)機(jī)構(gòu)邊欄排序(只取前三)
hot_orgs = all_courses.order_by('-click_nums')[:3]
# 學(xué)習(xí)人數(shù)及課程數(shù)排序
sort = request.GET.get('sort', '')
if sort:
if sort == 'students':
all_courses = all_courses.order_by('-students')
elif sort == 'courses':
all_courses = all_courses.order_by('-course_nums')
# 篩選條件
# 城市篩選
city_id = request.GET.get('city_id', '')
if city_id:
all_courses = all_courses.filter(city_id=int(city_id))
# 結(jié)構(gòu)類別篩選
category = request.GET.get('ct', '')
if category:
all_courses = all_courses.filter(category=category)
# 分頁功能展示
try:
page = request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
p = Paginator(all_courses, 5, request=request)
all_orgs = p.page(page)
org_nums = all_courses.count()
all_citys = CityDict.objects.all()
return render(request, 'org_list.html', {
'all_courses': all_orgs,
'all_citys': all_citys,
'org_nums': org_nums,
'city_id': city_id,
'category': category,
'hot_orgs': hot_orgs,
'sort': sort
})
每個(gè)app中url統(tǒng)一處理必盖,modelform使用
- url 統(tǒng)一處理include的使用
單個(gè)app中的url
# _*_ encoding:utf-8 _*_
__author__ = 'wrj008'
__date__ = '2018/3/13 14:45'
from django.conf.urls import url, include
from .views import OrgListView
urlpatterns = [
url(r'^list/$', OrgListView.as_view(), name='org_list'),
]
統(tǒng)一結(jié)構(gòu)中的url
url(r'^org/', include('organization.urls', namespace='org')),
- modelform 使用 通過forms 繼承model的形式拌牲,并添加過濾函數(shù)條件完成表單驗(yàn)證俱饿。本次的form提交 是異步操作歌粥,返回使用json格式的數(shù)據(jù)。
# _*_ encoding:utf-8 _*_
__author__ = 'wrj008'
__date__ = '2018/3/13 14:49'
from django import forms
import re
from operation.models import UserAsk
class UserAskForm(forms.ModelForm):
class Meta:
model = UserAsk
fields = ['name', 'mobile', 'course_name']
def clean_mobile(self):
mobile = self.cleaned_data['mobile']
REGEX_MOBILE = '^1[358]\d{9}$|^147\d{8}$|^176\d{8}$'
p = re.compile(REGEX_MOBILE)
if p.match(mobile):
return mobile
else:
raise forms.ValidationError(u'手機(jī)號不合法', code='invalid_mobile')
異步實(shí)現(xiàn)數(shù)據(jù)交互 使用
class AddUserAskView(View):
def post(self,request):
user_from = UserAskForm(request.POST)
if user_from.is_valid():
user = user_from.save(commit=True)
return HttpResponse({'status': 'success'}, content_type='application/json')
else:
return HttpResponse({'status': 'fail', 'msg': u'添加錯(cuò)誤'}, content_type='application/json')
機(jī)構(gòu)詳情頁功能實(shí)現(xiàn)
- 機(jī)構(gòu)首頁
已基礎(chǔ)也為準(zhǔn)拍埠,其中首頁返回內(nèi)容失驶,需要通過外鍵的反查詢方案實(shí)行,通過django的外鍵的set功能實(shí)現(xiàn)外鍵表內(nèi)容的獲取枣购。
基礎(chǔ)頁
<!DOCTYPE html>
<html>
{% load staticfiles %}
<head>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" >
<title>{% block title %}機(jī)構(gòu)首頁{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="/static/css/reset.css">
<link rel="stylesheet" type="text/css" href="/static/css/animate.css">
<link rel="stylesheet" type="text/css" href="/static/css/style.css">
<link rel="stylesheet" type="text/css" href="/static/js/plugins/queryCity/css/cityLayout.css">
{% block custon_css %}{% endblock %}
<script src="/static/js/jquery.min.js" type="text/javascript"></script>
<script src="/static/js/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>
{% block custom_js %}{% endblock %}
</head>
<body>
<section class="headerwrap headerwrap2">
<header>
<div class="header2 header">
<div class="top">
<div class="wp">
<div class="fl">
<p>聯(lián)系方式:<b>3333333333</b></p>
</div>
<a style="color:white" class="fr registerbtn" href="register.html">注冊</a>
<a style="color:white" class="fr loginbtn" href="login.html">登錄</a>
</div>
</div>
<div class="middle companyheader">
<div class="wp">
<img class="fl" style="width: 112px;height: 103px" src="{{ MEDIA_URL }}{{ org_detail.image }}"/>
<div class="head fl">
<h1>
{{ org_detial.name }}
<img src="/static/images/authentication.png"/>
<img src="/static/images/gold.png"/>
</h1>
<p class="fl">
<span class="fl" style="margin-top:8px;color:#848484;">推薦指數(shù): </span>
<span class="precision company-credit" data-star-scope="5.0"></span>
<span class="key">5.0</span>
</p>
</div>
<div class="btn fr collectionbtn notlogin
"data-favid="22" data-fav-type="1">
收藏
</div>
</div>
</div>
</div>
</header>
</section>
<section>
<div class="wp">
<ul class="crumbs">
<li><a href="index.html">首頁</a>></li>
<li><a href="org-list.html">課程機(jī)構(gòu)</a>></li>
<li>{% block custom_bread %}機(jī)構(gòu)首頁{% endblock %}</li>
</ul>
</div>
</section>
<section>
<div class="wp list personal_list comp">
<div class="left">
<ul>
<li class="{% ifequal current_page 'home' %}active2{% endifequal %}"><a href="{% url 'org:org_home' org_detail.id%}">機(jī)構(gòu)首頁</a></li>
<li class="{% ifequal current_page 'course' %}active2{% endifequal %}"><a href="{% url 'org:org_course' org_detail.id%}">機(jī)構(gòu)課程</a></li>
<li class=""><a href="org-detail-desc.html">機(jī)構(gòu)介紹</a></li>
<li class=""><a href="org-detail-teachers.html">機(jī)構(gòu)講師</a></li>
</ul>
</div>
{% block custom_right %}{% endblock %}
</section>
<!--sidebar start-->
<section>
<ul class="sidebar">
<li class="qq">
<a target="_blank" ></a>
</li>
<li class="totop"></li>
</ul>
</section>
<!--sidebar end-->
<!--header start-->
</div>
<!--彈出省省市-->
<script src="/static/js/selectUi.js" type='text/javascript'></script>
<script type="text/javascript" src="/static/js/plugins/laydate/laydate.js"></script>
<script src="/static/js/plugins/layer/layer.js"></script>
<script src="/static/js/plugins/queryCity/js/public.js" type="text/javascript"></script>
<script type="text/javascript" src="/static/js/plugins/jquery.raty.js"></script>
<script type="text/javascript">
//收藏分享
//收藏分享
function add_fav(current_elem, fav_id, fav_type){
$.ajax({
cache: false,
type: "POST",
url:"/org/add_fav/",
data:{'fav_id':fav_id, 'fav_type':fav_type},
async: true,
beforeSend:function(xhr, settings){
xhr.setRequestHeader("X-CSRFToken", "5I2SlleZJOMUX9QbwYLUIAOshdrdpRcy");
},
success: function(data) {
if(data.status == 'fail'){
if(data.msg == '用戶未登錄'){
window.location.href="login.html";
}else{
alert(data.msg)
}
}else if(data.status == 'success'){
current_elem.text(data.msg)
}
},
});
}
$('.collectionbtn').on('click', function(){
add_fav($(this), 1, 2);
});
$(function(){
var $precision = $('.precision'),
score = $precision.attr('data-star-scope'),
option = {
half : true,
path : '{% static 'images/' %}',
precision : true,
size : 24,
starOff : 'g_star.png',
starOn : 'r_star.png',
starHalf : 'h_star.png',
hints : ['極差', '差', '一般', '好評', '非常滿意'],
noRatedMsg : '暫時(shí)還未獲得評價(jià)嬉探!',
readOnly : true,
score : score
};
$precision.raty(option);
$('.jsFavBtn').on('click', function(){
var type = $(this).attr('data-fav-type');
if(type == '1'){
favPraise($(this), 'fav' ,1 , '收藏');
}else if(type == '3'){
favPraise($(this), 'fav' ,3 );
}else if(type == '11'){
favPraise($(this), 'pra', 1);
}else if(type == '4'){
favPraise($(this), 'fav' ,4 );
}
});
})
</script>
<script type="text/javascript">
$(function() {
$('.recordbtn1').click(function(){
$('.recordbox1').show();
});
$('.recordbtn2').click(function(){
$('.recordbox2').show();
});
$('.imgslide').unslider({
speed: 500, // The speed to animate each slide (in milliseconds)
delay: 3000, // The delay between slide animations (in milliseconds)
complete: function() {}, // A function that gets called after every slide animation
keys: true, // Enable keyboard (left, right) arrow shortcuts
dots: true, // Display dot navigation
fluid: false // Support responsive design. May break non-responsive designs
});
var unslider = $('.imgslide').unslider();
$('.unslider-arrow').click(function() {
var fn = this.className.split(' ')[1];
unslider.data('unslider')[fn]();
});
});
</script>
</body>
</html>
詳情頁
{% extends 'common/org_detail_base.html' %}
{% block title %} 機(jī)構(gòu)首頁 {% endblock %}
{% block custom_bread %}機(jī)構(gòu)首頁{% endblock %}
{% block custom_right %}
<div class="right companycenter layout grouping" >
<div class="head">
<h1>全部課程</h1>
<a class="green fr more" href="org-detail-course.html">查看更多 > </a>
</div>
<div class="brief group_list">
{% for course in all_course %}
<div class="module1_5 box">
<a href="course-detail.html"><img width="214" src="{{ MEDIA_URL }}{{ course.image }}"/></a>
<div class="des">
<a href="course-detail.html"><h2>{{ course.name }}</h2></a>
<span class="fl">課時(shí):<i class="key">{{ course.learn_time }}</i></span>
<span class="fr">參加人數(shù):{{ course.students }}</span>
</div>
<div class="bottom">
<span class="fl">{{ course.course_org.name }}</span>
<span class="star fr notlogin
" data-favid="13" data-fav-type="4">
{{ course.fav_nums }}
</span>
</div>
</div>
{% endfor %}
</div>
</div>
<div class="right companycenter layout" >
<div class="head">
<h1>機(jī)構(gòu)教師</h1>
<a class="green fr more" href="org-detail-teachers.html">查看更多 > </a>
</div>
{% for teacher in all_teacher %}
<div class="diarys">
<div class="module5 share company-diary-box" style="padding:10px 0;">
<div class="left">
<img class="pic" src="{{ MEDIA_URL }}{{ teacher.image }}"/>
<p>{{ teacher.name }}</p>
</div>
<div class="right">
<div class="top">
<div class="fl">
<a href=""><h1>java開發(fā)教程</h1></a>
<span>發(fā)表于:2015-10-12</span>
</div>
</div>
<div class="middle" style="border-bottom:0;">課程介紹</div>
</div>
</div>
</div>
{% endfor %}
</div>
<div class="right companycenter layout" >
<div class="head">
<h1>機(jī)構(gòu)介紹</h1>
<a class="green fr more" href="org-detail-desc.html">查看更多 > </a>
</div>
<div class="cont"> <p> </p>{{ org_detail.desc }}<a href="/company/desc/22/"><span class="green">[查看更多]</span></a></div>
</div>
{% endblock %}
內(nèi)容返回
class OrgDetailHomeView(View):
"""
機(jī)構(gòu)詳情頁
"""
def get(self, request, org_id):
current_page = 'home'
org_detail = CourseOrg.objects.get(id=int(org_id))
all_course = org_detail.course_set.all()[:3]
all_teacher = org_detail.teacher_set.all()[:1]
return render(request, 'org-detail-homepage.html', {
'all_course': all_course,
'all_teacher': all_teacher,
'org_detail': org_detail,
'current_page': current_page
})
- 機(jī)構(gòu)課程
與機(jī)構(gòu)首頁基本相似
詳情頁
{% extends 'common/org_detail_base.html' %}
{% block title %} 機(jī)構(gòu)課程 {% endblock %}
{% block custom_bread %}機(jī)構(gòu)課程{% endblock %}
{% block custom_right %}
<div class="right companycenter layout" >
<div class="head">
<h1>機(jī)構(gòu)課程</h1>
</div>
<div class="brief group_list">
{% for course in all_course %}
<div class="module1_5 box">
<a class="comp-img-box" href="course-detail.html">
<img width="214" height="195" src="{{ MEDIA_URL }}{{ course.image }}"/>
</a>
<div class="des">
<a href="course-detail.html"><h2>{{ course.name }}</h2></a>
<span class="fl">課時(shí):<i class="key">{{ course.learn_time }}</i></span>
<span class="fr">學(xué)習(xí)人數(shù):{{ course.students }}</span>
</div>
<div class="bottom">
<span class="fl">{{ course.course_org.name }}</span>
<span class="star fr notlogin
" data-favid="13" data-fav-type="4">
{{ course.fav_nums }}
</span>
</div>
</div>
{% endfor %}
</div>
<div class="pageturn">
<ul class="pagelist">
<li class="active"><a href="?page=1">1</a></li>
</ul>
</div>
</div>
{% endblock %}
返回結(jié)果
class OrgDetailCourseView(View):
"""
機(jī)構(gòu)課程頁
"""
def get(self, request, org_id):
current_page = 'course'
org_detail = CourseOrg.objects.get(id=int(org_id))
all_course = org_detail.course_set.all()
return render(request, 'org-detail-course.html', {
'all_course': all_course,
'org_detail': org_detail,
'current_page': current_page
})
- 機(jī)構(gòu)介紹
操作與之前的操作一樣擦耀,只是返回結(jié)果變少了。
class OrgDetailCourseView(View):
"""
機(jī)構(gòu)課程頁
"""
def get(self, request, org_id):
current_page = 'course'
org_detail = CourseOrg.objects.get(id=int(org_id))
has_fav = False
if request.user.is_authenticated():
if UserFavorite.objects.filter(user=request.user, fav_id=org_detail.id, fav_type=2):
has_fav = True
all_course = org_detail.course_set.all()
return render(request, 'org-detail-course.html', {
'all_course': all_course,
'org_detail': org_detail,
'current_page': current_page,
'has_fav': has_fav
})
- 機(jī)構(gòu)講師
操作與之前的操作一樣涩堤,只是返回結(jié)果變少了眷蜓。
class OrgDetailDescView(View):
"""
機(jī)構(gòu)詳情頁
"""
def get(self, request, org_id):
current_page = 'desc'
org_detail = CourseOrg.objects.get(id=int(org_id))
has_fav = False
if request.user.is_authenticated():
if UserFavorite.objects.filter(user=request.user, fav_id=org_detail.id, fav_type=2):
has_fav = True
return render(request, 'org-detail-desc.html', {
'org_detail': org_detail,
'current_page': current_page,
'has_fav': has_fav
})
用戶收藏以及取消收藏
<!DOCTYPE html>
<html>
{% load staticfiles %}
<head>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" >
<title>{% block title %}機(jī)構(gòu)首頁{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="/static/css/reset.css">
<link rel="stylesheet" type="text/css" href="/static/css/animate.css">
<link rel="stylesheet" type="text/css" href="/static/css/style.css">
<link rel="stylesheet" type="text/css" href="/static/js/plugins/queryCity/css/cityLayout.css">
{% block custom_js %}{% endblock %}
<script src="{% static 'js/jquery.min.js' %}" type="text/javascript"></script>
<script src="/static/js/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>
</head>
<body>
<section class="headerwrap headerwrap2">
<header>
<div class="header2 header">
<div class="top">
<div class="wp">
<div class="fl">
<p>聯(lián)系方式:<b>3333333333</b></p>
</div>
{% if request.user.is_authenticated %}
<div class="personal">
<dl class="user fr">
<dd>bobby<img class="down fr" src="/static/images/top_down.png"/></dd>
<dt><img width="20" height="20" src="/static/media/image/2016/12/default_big_14.png"/></dt>
</dl>
<div class="userdetail">
<dl>
<dt><img width="80" height="80" src="/static/media/image/2016/12/default_big_14.png"/></dt>
<dd>
<h2>django</h2>
<p>bobby</p>
</dd>
</dl>
<div class="btn">
<a class="personcenter fl" href="usercenter-info.html">進(jìn)入個(gè)人中心</a>
<a class="fr" href="/logout/">退出</a>
</div>
</div>
</div>
{% else %}
<a style="color:white" class="fr registerbtn" href="{% url 'register' %}">注冊</a>
<a style="color:white" class="fr loginbtn" href="/login/">登錄</a>
{% endif %}
</div>
</div>
<div class="middle companyheader">
<div class="wp">
<img class="fl" style="width: 112px;height: 103px" src="{{ MEDIA_URL }}{{ org_detail.image }}"/>
<div class="head fl">
<h1>
{{ org_detial.name }}
<img src="/static/images/authentication.png"/>
<img src="/static/images/gold.png"/>
</h1>
<p class="fl">
<span class="fl" style="margin-top:8px;color:#848484;">推薦指數(shù): </span>
<span class="precision company-credit" data-star-scope="5.0"></span>
<span class="key">5.0</span>
</p>
</div>
<div class="btn fr collectionbtn notlogin
"data-favid="22" data-fav-type="1" id="fav_add">
{% if has_fav %}已收藏{% else %}收藏{% endif %}
</div>
</div>
</div>
</div>
</header>
</section>
<section>
<div class="wp">
<ul class="crumbs">
<li><a href="index.html">首頁</a>></li>
<li><a href="org-list.html">課程機(jī)構(gòu)</a>></li>
<li>{% block custom_bread %}機(jī)構(gòu)首頁{% endblock %}</li>
</ul>
</div>
</section>
<section>
<div class="wp list personal_list comp">
<div class="left">
<ul>
<li class="{% ifequal current_page 'home' %}active2{% endifequal %}"><a href="{% url 'org:org_home' org_detail.id%}">機(jī)構(gòu)首頁</a></li>
<li class="{% ifequal current_page 'course' %}active2{% endifequal %}"><a href="{% url 'org:org_course' org_detail.id%}">機(jī)構(gòu)課程</a></li>
<li class="{% ifequal current_page 'desc' %}active2{% endifequal %}"><a href="{% url 'org:org_desc' org_detail.id%}">機(jī)構(gòu)介紹</a></li>
<li class="{% ifequal current_page 'teacher' %}active2{% endifequal %}"><a href="{% url 'org:org_teacher' org_detail.id%}">機(jī)構(gòu)講師</a></li>
</ul>
</div>
{% block custom_right %}{% endblock %}
</section>
<!--sidebar start-->
<section>
<ul class="sidebar">
<li class="qq">
<a target="_blank" ></a>
</li>
<li class="totop"></li>
</ul>
</section>
<!--sidebar end-->
<!--header start-->
</div>
<!--彈出省省市-->
<script src="/static/js/selectUi.js" type='text/javascript'></script>
<script type="text/javascript" src="/static/js/plugins/laydate/laydate.js"></script>
<script src="/static/js/plugins/layer/layer.js"></script>
<script src="/static/js/plugins/queryCity/js/public.js" type="text/javascript"></script>
<script type="text/javascript" src="/static/js/unslider.js"></script>
<script type="text/javascript" src="/static/js/plugins/jquery.raty.js"></script>
<script type="text/javascript">
//收藏分享
$('.collectionbtn').on('click', function(){
add_fav($(this), {{ org_detail.id }}, 2);
});
//收藏分享
function add_fav(current_elem, fav_id, fav_type){
$.ajax({
cache: false,
type: "POST",
url:"{% url 'org:add_fav' %}",
data:{'fav_id':fav_id, 'fav_type':fav_type},
dataType: "json",
async: true,
beforeSend:function(xhr, settings){
xhr.setRequestHeader("X-CSRFToken"," {{ csrf_token }}");
},
success: function(data) {
if(data.status == 'fail'){
if(data.msg == '用戶未登錄'){
window.location.href="{% url 'login' %}";
}else{
alert(data.msg)
}
}else if(data.status == 'success'){
current_elem.text(data.msg)
}
},
});
}
$(function(){
var $precision = $('.precision'),
score = $precision.attr('data-star-scope'),
option = {
half : true,
path : '{% static 'images/' %}',
precision : true,
size : 24,
starOff : 'g_star.png',
starOn : 'r_star.png',
starHalf : 'h_star.png',
hints : ['極差', '差', '一般', '好評', '非常滿意'],
noRatedMsg : '暫時(shí)還未獲得評價(jià)!',
readOnly : true,
score : score
};
$precision.raty(option);
$('.jsFavBtn').on('click', function(){
var type = $(this).attr('data-fav-type');
if(type == '1'){
favPraise($(this), 'fav' ,1 , '收藏');
}else if(type == '3'){
favPraise($(this), 'fav' ,3 );
}else if(type == '11'){
favPraise($(this), 'pra', 1);
}else if(type == '4'){
favPraise($(this), 'fav' ,4 );
}
});
})
</script>
<script type="text/javascript">
$(function() {
$('.recordbtn1').click(function(){
$('.recordbox1').show();
});
$('.recordbtn2').click(function(){
$('.recordbox2').show();
});
$('.imgslide').unslider({
speed: 500, // The speed to animate each slide (in milliseconds)
delay: 3000, // The delay between slide animations (in milliseconds)
complete: function() {}, // A function that gets called after every slide animation
keys: true, // Enable keyboard (left, right) arrow shortcuts
dots: true, // Display dot navigation
fluid: false // Support responsive design. May break non-responsive designs
});
var unslider = $('.imgslide').unslider();
$('.unslider-arrow').click(function() {
var fn = this.className.split(' ')[1];
unslider.data('unslider')[fn]();
});
});
</script>
</body>
</html>
class AddFavView(View):
"""
添加收藏
"""
def post(self, request):
fav_id = request.POST.get('fav_id', 0)
fav_type = request.POST.get('fav_type', 0)
if not request.user.is_authenticated():
return HttpResponse({'status': 'fail', 'msg': '用戶未登錄'}, content_type='application/json')
existed_record = UserFavorite.objects.filter(user=request.user, fav_id=int(fav_id), fav_type=int(fav_type))
if existed_record:
existed_record.delete()
return HttpResponse({'status': 'success', 'msg': '收藏'}, content_type='application/json')
else:
user_fav = UserFavorite()
if int(fav_id) > 0 and int(fav_type) > 0:
user_fav.user = request.user
user_fav.fav_id = int(fav_id)
user_fav.fav_type = int(fav_type)
user_fav.save()
return HttpResponse({'status': 'success', 'msg': '已收藏'}, content_type='application/json')
else:
return HttpResponse({'status': 'fail', 'msg': '收藏錯(cuò)誤'}, content_type='application/json')
其他頁面收藏顯示選擇一個(gè)做講解胎围,通過添加一個(gè)變量做標(biāo)識吁系,如果用戶登錄并且已經(jīng)收藏,那么則變量為true,如果沒有則false
class OrgDetailTeacherView(View):
"""
機(jī)構(gòu)教師頁
"""
def get(self, request, org_id):
current_page = 'teacher'
org_detail = CourseOrg.objects.get(id=int(org_id))
has_fav = False
if request.user.is_authenticated():
if UserFavorite.objects.filter(user=request.user, fav_id=org_detail.id, fav_type=2):
has_fav = True
all_teacher = org_detail.teacher_set.all()
return render(request, 'org-detail-teachers.html', {
'all_teacher': all_teacher,
'org_detail': org_detail,
'current_page': current_page,
'has_fav': has_fav
})
- 用戶登錄注冊顯示
{% if request.user.is_authenticated %}
<div class="personal">
<dl class="user fr">
<dd>bobby<img class="down fr" src="/static/images/top_down.png"/></dd>
<dt><img width="20" height="20" src="/static/media/image/2016/12/default_big_14.png"/></dt>
</dl>
<div class="userdetail">
<dl>
<dt><img width="80" height="80" src="/static/media/image/2016/12/default_big_14.png"/></dt>
<dd>
<h2>django</h2>
<p>bobby</p>
</dd>
</dl>
<div class="btn">
<a class="personcenter fl" href="usercenter-info.html">進(jìn)入個(gè)人中心</a>
<a class="fr" href="/logout/">退出</a>
</div>
</div>
</div>
{% else %}
<a style="color:white" class="fr registerbtn" href="{% url 'register' %}">注冊</a>
<a style="color:white" class="fr loginbtn" href="/login/">登錄</a>
{% endif %}
- 本篇博客原視頻博主[慕課在線教育平臺]
- 本篇博客撰寫人: XiaoJinZi 轉(zhuǎn)載請注明出處
- 學(xué)生能力有限 附上郵箱: 986209501@qq.com 不足以及誤處請大佬指責(zé)