美文网首页
第九章 在线教育平台(功能完善,首页功能开发)

第九章 在线教育平台(功能完善,首页功能开发)

作者: Xia0JinZi | 来源:发表于2018-03-19 19:51 被阅读0次

    页面功能完善

    标签:django


    功能完善

    首页
    • 登出操作

    通过调用django中自带logout。

    class LogoutView(View):
        def get(self, request):
            logout(request)
            from django.core.urlresolvers import reverse
            return HttpResponseRedirect(reverse('index'))
    
    • 课程,机构讲师点击量增加

    在所有的详情页 中对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')
    
    
    • 未读消息内容的标签内容

    当用户进入消息中心,则将所有消息变成已读。

    首页功能实现

    {% 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">专业权威</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">数据真实</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/>专业权威</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">学习人数:{{ course.students }}</span>
                                    </div>
                                    <div class="bottom">
                                        <span class="fl" title="慕课网">{{ 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>课程机构</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/>权威认证</p>
                            <a class="more" href="org-list.html">查看更多机构 ></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):
        """
        首页页面动态数据加载
        """
        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下面添加页面出错问题函数配置

    # 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
    
    • 生产环境下 静态文件的路劲配置

    这里的变更会使xadmin后台样式受影响,后期内容在做修改。错误页面只有在生产环境下才能生效。

    DEBUG = False
    
    ALLOWED_HOSTS = ['*']
    
    

    添加静态文件访问路径,与media 文件一样。修改变更内容。

    STATIC_ROOT = os.path.join(BASE_DIR, 'static')
    
    
    url(r'^static/(?P<path>.*)/$', serve, {'document_root': STATIC_ROOT}),
    
    • 针对xadmin样式内容不限显示
    xadmin后台样式出错
    需将后台xadmin下面的static下的xadmin文件拷贝至项目的初始static文件下
    
    图标不显示 需将font awesome中的fonts文件放入css下
    
    富文本样式同样考入static文件下
    
    具体如下图
    
    后台样式文件配置 后台图标显示 富文本内容显示
    • 本篇博客原视频博主[慕课在线教育平台]
    • 本篇博客撰写人: XiaoJinZi 转载请注明出处
    • 学生能力有限 附上邮箱: 986209501@qq.com 不足以及误处请大佬指责

    相关文章

      网友评论

          本文标题:第九章 在线教育平台(功能完善,首页功能开发)

          本文链接:https://www.haomeiwen.com/subject/wnapqftx.html