頁面功能完善
標(biāo)簽:django
功能完善
- 登出操作
通過調(diào)用django中自帶logout踪栋。
class LogoutView(View):
def get(self, request):
logout(request)
from django.core.urlresolvers import reverse
return HttpResponseRedirect(reverse('index'))
- 課程祭饭,機構(gòu)講師點擊量增加
在所有的詳情頁 中對clicknum+1操作
- 收藏量的增加與減少
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()
if int(fav_type) == 1:
course = Course.objects.get(id=int(fav_id))
course.fav_nums -= 1
if course.fav_nums < 0:
course.fav_nums = 0
course.save()
if int(fav_type) == 2:
course_org = CourseOrg.objects.get(id=int(fav_id))
course_org.fav_nums -= 1
if course_org.fav_nums < 0:
course_org.fav_nums = 0
course_org.save()
if int(fav_type) == 3:
teacher = Teacher.objects.get(id=int(fav_id))
teacher.fav_nums -= 1
if teacher.fav_nums < 0:
teacher.fav_nums = 0
teacher.save()
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()
if int(fav_type) == 1:
course = Course.objects.get(id=int(fav_id))
course.fav_nums += 1
course.save()
if int(fav_type) == 2:
course_org = CourseOrg.objects.get(id=int(fav_id))
course_org.fav_nums += 1
course_org.save()
if int(fav_type) == 3:
teacher = Teacher.objects.get(id=int(fav_id))
teacher.fav_nums += 1
teacher.save()
return HttpResponse('{"status": "success", "msg": "已收藏"}', content_type='application/json')
else:
return HttpResponse('{"status": "fail", "msg": "收藏錯誤"}', content_type='application/json')
- 未讀消息內(nèi)容的標(biāo)簽內(nèi)容
當(dāng)用戶進入消息中心,則將所有消息變成已讀盹舞。
首頁功能實現(xiàn)
{% extends 'common/base.html' %}
{% load staticfiles %}
{% block custom_bread %}
{% endblock %}
{% block custom_js %}
<script type="text/javascript" src="/static/js/index.js"></script>
{% endblock %}
{% block custom_content %}
<div class="banner">
<div class="wp">
<div class="fl">
<div class="imgslide">
<ul class="imgs">
{% for banner in banners %}
<li>
<a href="{{ banner.url }}">
<img width="1200" height="478" src="{{ MEDIA_URL }}{{ banner.image }}" />
</a>
</li>
{% endfor %}
</ul>
</div>
<div class="unslider-arrow prev"></div>
<div class="unslider-arrow next"></div>
</div>
</div>
</div>
<!--banner end-->
<!--feature start-->
<section>
<div class="wp">
<ul class="feature">
<li class="feature1">
<img class="pic" src="/static/images/feature1.png"/>
<p class="center">專業(yè)權(quán)威</p>
</li>
<li class="feature2">
<img class="pic" src="/static/images/feature2.png"/>
<p class="center">課程最新</p>
</li>
<li class="feature3">
<img class="pic" src="/static/images/feature3.png"/>
<p class="center">名師授課</p>
</li>
<li class="feature4">
<img class="pic" src="/static/images/feature4.png"/>
<p class="center">數(shù)據(jù)真實</p>
</li>
</ul>
</div>
</section>
<!--feature end-->
<!--module1 start-->
<section>
<div class="module">
<div class="wp">
<h1>公開課程</h1>
<div class="module1 eachmod">
<div class="module1_1 left">
<img width="228" height="614" src="/static/images/module1_1.jpg"/>
<p class="fisrt_word">名師授課<br/>專業(yè)權(quán)威</p>
<a class="more" href="course-list.html">查看更多課程 ></a>
</div>
<div class="right group_list">
<div class="module1_2 box">
<div class="imgslide2">
<ul class="imgs">
{% for is_course in is_courses %}
<li>
<a href="{% url 'course:course_detail' is_course.id %}">
<img width="470" height="300" src="{{ MEDIA_URL }}{{ is_course.image }}" />
</a>
</li>
{% endfor %}
</ul>
</div>
<div class="unslider-arrow2 prev"></div>
<div class="unslider-arrow2 next"></div>
</div>
{% for course in courses %}
<div class="module1_{{ forloop.counter|add:2 }} box">
<a href="{% url 'course:course_detail' course.id %}">
<img width="233" height="190" src="{{ MEDIA_URL }}{{ course.image }}"/>
</a>
<div class="des">
<a href="{% url 'course:course_detail' course.id %}">
<h2 title="{{ course.name }}">{{ course.name }}</h2>
</a>
<span class="fl">難度:<i class="key">{{ course.get_degree_display() }}</i></span>
<span class="fr">學(xué)習(xí)人數(shù):{{ course.students }}</span>
</div>
<div class="bottom">
<span class="fl" title="慕課網(wǎng)">{{ course.course_org.name }}</span>
<span class="star fr">{{ course.fav_nums }}</span>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
</section>
<section>
<div class="module greybg">
<div class="wp">
<h1>課程機構(gòu)</h1>
<div class="module3 eachmod">
<div class="module3_1 left">
<img width="228" height="463" src="/static/images/module3_1.jpg"/>
<p class="fisrt_word">名校來襲<br/>權(quán)威認證</p>
<a class="more" href="org-list.html">查看更多機構(gòu) ></a>
</div>
<div class="right">
<ul>
{% for course_org in course_orgs %}
<li class="{% if forloop.counter|divisibleby:5 %}five{% endif %}">
<a href="{% url 'org:org_home' course_org.id %}">
<div class="company">
<img width="184" height="100" src="{{ MEDIA_URL }}{{ course_org.image }}"/>
<div class="score">
<div class="circle">
<h2>{{ course_org.tag }}</h2>
</div>
</div>
</div>
<p><span class="key" title="{{ course_org.name }}">{{ course_org.name }}</span></p>
</a>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
</section>
{% endblock %}
class IndexView(View):
"""
首頁頁面動態(tài)數(shù)據(jù)加載
"""
def get(self, request):
banners = Banner.objects.all().order_by('index')
courses = Course.objects.filter(is_banner=False)[:7]
is_courses = Course.objects.filter(is_banner=True)[:3]
course_orgs = CourseOrg.objects.all().order_by('-click_nums')[:15]
return render(request, 'index.html', {
'banners': banners,
'courses': courses,
'is_courses': is_courses,
'course_orgs': course_orgs
})
公共頁面的處理
- 404頁面處理
在公共url下面添加頁面出錯問題函數(shù)配置
# page not found
handler404 = 'users.views.page_not_found'
handler500 = 'users.views.page_error'
handler403 = 'users.views.page_forbiden'
def page_not_found(request):
# 404 界面配置
from django.shortcuts import render_to_response
response = render_to_response('common/404.html', {})
response.status_code = 404
return response
def page_error(request):
# 500 界面配置
from django.shortcuts import render_to_response
response = render_to_response('common/500.html', {})
response.status_code = 500
return response
def page_forbiden(request):
# 403 界面配置
from django.shortcuts import render_to_response
response = render_to_response('common/403.html', {})
response.status_code = 403
return response
- 生產(chǎn)環(huán)境下 靜態(tài)文件的路勁配置
這里的變更會使xadmin后臺樣式受影響,后期內(nèi)容在做修改隘庄。錯誤頁面只有在生產(chǎn)環(huán)境下才能生效踢步。
DEBUG = False
ALLOWED_HOSTS = ['*']
添加靜態(tài)文件訪問路徑,與media 文件一樣丑掺。修改變更內(nèi)容获印。
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
url(r'^static/(?P<path>.*)/$', serve, {'document_root': STATIC_ROOT}),
- 針對xadmin樣式內(nèi)容不限顯示
xadmin后臺樣式出錯
需將后臺xadmin下面的static下的xadmin文件拷貝至項目的初始static文件下
圖標(biāo)不顯示 需將font awesome中的fonts文件放入css下
富文本樣式同樣考入static文件下
具體如下圖
- 本篇博客原視頻博主[慕課在線教育平臺]
- 本篇博客撰寫人: XiaoJinZi 轉(zhuǎn)載請注明出處
- 學(xué)生能力有限 附上郵箱: 986209501@qq.com 不足以及誤處請大佬指責(zé)