码迷,mamicode.com
首页 > 其他好文 > 详细

Django+xadmin打造在线教育平台(五)

时间:2019-11-10 15:25:26      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:admin   搜索   model   padding   add   django   from   content   ssh   

九、机构模块

1、机构列表展示

(1)构造url

# orgs/urls.py

from django.urls import path
from .views import *

app_name = orgs

urlpatterns = [
    path(org_list, org_list, name=org_list)
]

(2)视图函数编写

# orgs/views.py
from django.shortcuts import render
from .models import OrgInfo, TeacherInfo, CityInfo
# Create your views here.


def org_list(request):
    all_orgs = OrgInfo.objects.all()
    return render(request, org-list.html, {
        all_orgs: all_orgs
    })

(3)前端页面

将资料包中org-list.html拷贝到templates目录下

经过前面的html抽象base,我们直接继承base.html

技术图片
{% extends ‘base.html‘ %}
{% block title %}
    课程机构列表 - 谷粒教育网
{% endblock %}
{% block content %}
    <section>
        <div class="wp">
            <ul  class="crumbs">
                <li><a href="index.html">首页</a>></li>
                <li>课程机构</li>
            </ul>
        </div>
    </section>
    <section>
    <div class="wp butler_list_box list">
    <div class=‘left‘>
        <div class="listoptions">
            <ul>
                <li>
                    <h2>机构类别</h2>
                    <div class="cont">
                        <a href="?city="><span class="active2">全部</span></a>

                            <a href="?ct=pxjg&city="><span class="">培训机构</span></a>

                            <a href="?ct=gx&city="><span class="">高校</span></a>

                            <a href="?ct=gr&city="><span class="">个人</span></a>

                    </div>
                </li>
                <li>
                    <h2>所在地区</h2>
                    <div class="more">更多</div>
                    <div class="cont">
                        <a href="?ct="><span class="active2">全部</span></a>

                                <a href="?city=1&ct="><span class="">北京市</span></a>

                                <a href="?city=2&ct="><span class="">上海市</span></a>

                                <a href="?city=3&ct="><span class="">广州市</span></a>

                                <a href="?city=4&ct="><span class="">深圳市</span></a>
                    </div>
                </li>
            </ul>
        </div>
        <div class="all"><span class="key">15</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=">学习人数 &#8595;</a></li>
                    <li class=""><a href="?sort=courses&ct=&city=">课程数 &#8595;</a></li>
                </ul>
            </div>

                <dl class="des difdes">
                    <dt>
                        <a href="org-detail-homepage.html">
                            <img width="200" height="120" class="scrollLoading" data-url="../images/org.png"/>
                        </a>
                    </dt>
                    <dd>
                        <div class="clearfix">
                             <a href="org-detail-homepage.html">
                                 <h1>谷粒教育网</h1>
                                 <div class="pic fl">

                                         <img src="../images/authentication.png"/>

                                         <img src="../images/gold.png"/>

                                 </div>
                             </a>
                        </div>
                        <ul class="cont">
                            <li class="first"><p class="pic9">课程数:<span>1</span></p><p class="c7">学习人数:<span>1000</span></p></li>
                            <li class="c8" style="padding-left:18px;">北京市昌平区北七家</li>
                            <li class="pic10" style="padding-left:18px;">经典课程:

                                    <a href="/diary/19/">mysql</a>

                                    <a href="/diary/16/">mongodb</a>

                            </li>
                        </ul>
                    </dd>
                    <div class="buy start_groupbuy jsShowPerfect2" data-id="22"><br/>联系<br/>服务</div>
                </dl>


        </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">我要学习</div>
            <form class="rightform" id="jsStayForm">
                <div>
                    <img src="../images/rightform1.png"/>
                    <input type="text" name="name" id="companyName" placeholder="名字" maxlength="25" />
                </div>
                <div>
                    <img src="../images/rightform2.png"/>
                    <input type="text" name="mobile" id="companyMobile" placeholder="联系电话"/>
                </div>
                <div>
                    <img src="../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">授课机构排名</div>


                <dl class="des">
                    <dt class="num fl">1</dt>
                    <dd>
                        <a href="/company/2/"><h1>尚硅谷</h1></a>
                        <p>北京市</p>
                    </dd>
                </dl>




        </div>
        </div>
</section>
{% endblock %}
org-list.html

(4)在base.html中给出接口

找到“授课机构”所在的标签,更改其中的url

<li ><a href="{% url ‘orgs:org_list‘ %}">授课机构</a></li>
技术图片
<!DOCTYPE html>
{% load staticfiles %}
<html>

<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" >
    <title>{% block title %}

    {% 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‘ %}">
    {% block mycss %}

    {% 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 ">
    <header>
        <div  class=" header">
             <div class="top">
                <div class="wp">
                    <div class="fl"><p>服务电话:<b>8888888</b></p></div>
                    <!--登录后跳转-->

                        {% if request.user.is_authenticated %}
                            <div class="personal">
                            <dl class="user fr">
                                <dd>{{ request.user.username }}<img class="down fr" src="{% static ‘images/top_down.png‘ %}"/></dd>
                                <dt><img width="20" height="20" src="{{ MEDIA_URL }}{{ request.user.image }}"/></dt>
                            </dl>
                            <div class="userdetail">
                                <dl>
                                    <dt><img width="80" height="80" src="{{ MEDIA_URL }}{{ request.user.image }}"/></dt>
                                    <dd>
                                        <h2>django</h2>
                                        <p>{{ request.user.username }}</p>
                                    </dd>
                                </dl>
                                <div class="btn">
                                    <a class="personcenter fl" href="usercenter-info.html">进入个人中心</a>
                                    <a class="fr" href="{% url ‘users:logout‘ %}">退出</a>
                                </div>
                            </div>
                        </div>
                        {% else %}
                            <a style="color:white" class="fr registerbtn" href="{% url ‘users:register‘ %}">注册</a>
                            <a style="color:white" class="fr loginbtn" href="{% url ‘users:login‘ %}">登录</a>
                        
                        {% endif %}

                </div>
            </div>
            {% block middle %}
            <div class="middle">
                <div class="wp">
                    <a href="index.html"><img class="fl" src="{% static ‘images/logo1.png‘ %}"/></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">课程机构</li>
                                <li data-value="teacher">授课老师</li>
                            </ul>
                        </div>
                        <input id="search_keywords" class="fl" type="text" value="" placeholder="请输入搜索内容"/>
                        <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 class="active" ><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 ><a href="{% url ‘orgs:org_list‘ %}">授课机构</a></li>
                        </ul>
                    </div>
                </div>
            </nav>
            {% endblock %}
            </div>
    </header>
</section>
{% block content %}

{% endblock %}

{% block footer %}
<footer>
        <div class="footer">
            <div class="wp">
                <ul class="cont">
                    <li class="logo"><a href=""><img src="{% static ‘images/logo1.png‘ %}"/></a></li>
                    <li class="code"><img src="{% static ‘images/code.jpg‘ %}"/><p class="center">扫描关注微信</p></li>
                    <li class="third"><img class="fl" src="{% static ‘images/tell.png‘ %}"/><p class="tell">88888888</p><p class="time">周一至周日 9:00-18:00</p></li>
                </ul>

            </div>
            <p class="line"></p>
            <div class="wp clear">
                <span class="fl">? 2012 www.atguigu.com谷粒教育-在线学习交流平台 保留所有权利</span>
                <span class="fr">copyright ? 2012 ICP备案证书号:蜀ICP备xxxxx号-1</span>
            </div>
        </div>
    </footer>
{% endblock %}


<section>
    <ul class="sidebar">
        <li class="qq">
            <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=2023525077&site=qq&menu=yes"></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 type="text/javascript" src="{% static ‘js/index.js‘ %}"></script>
{% block myjs %}

{% endblock %}
</body>
</html>
base.html完整代码

启动项目,点击“授课机构”,如下图所示。

技术图片

 

 

 

Django+xadmin打造在线教育平台(五)

标签:admin   搜索   model   padding   add   django   from   content   ssh   

原文地址:https://www.cnblogs.com/huiyichanmian/p/11829719.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!