码迷,mamicode.com
首页 > Web开发 > 详细

day4 url views

时间:2017-11-05 21:41:37      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:pre   size   role   static   art   day   lis   dmi   content   

1.显示用户名

技术分享

<li><a href="#">{{ request.user }}</a></li>

 

 

2.添加menu

 

 技术分享

技术分享

urlpatterns = [
    url(r^$, views.index,name=sales_index),  #ctrl + b 跳转
    url(r^customers/$,views.customer_list,name=custmoer_list),
]

 

def index(request):
    return render(request,index.html)

def customer_list(request):
    return render(request,sales/customers.html)

 

 

3.添加role

 

 

技术分享

技术分享技术分享

技术分享

 

 

 

 

4.实现效果

技术分享

 

        {% for  role in request.user.userprofile.roles.all %}
          {% for menu in role.menus.all %}
            <li class=""><a href="{%  url  menu.url_name %}">{{ menu.name }}</a></li>
          {% endfor %}
        {% endfor %}

 

 

 



 

 

 

 1.添加学生app

D:\PycharmProjects\PerfectCRM2>python manage.py startapp student

 

INSTALLED_APPS = [
    django.contrib.admin,
    django.contrib.auth,
    django.contrib.contenttypes,
    django.contrib.sessions,
    django.contrib.messages,
    django.contrib.staticfiles,
    crm,
    student,
]

 

 

 技术分享技术分享技术分享技术分享

 

 2.url

from django.conf.urls import url,include
from django.contrib import admin

urlpatterns = [
    url(r^admin/, admin.site.urls),
    url(r^crm/, include(crm.urls)),
    url(r^student/, include(student.urls)),    #添加url
]

 

#student中 urls.py

from django.conf.urls import url
from student import views
urlpatterns = [
    url(r^$,views.index,name=student_index),
]

 

#student中views.py

def index(request):
    return render(request,student/index.html)

 

3.实现效果

技术分享技术分享

 

day4 url views

标签:pre   size   role   static   art   day   lis   dmi   content   

原文地址:http://www.cnblogs.com/venicid/p/7788869.html

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