返回顶部

收藏

Django 利用url来控制登录

更多

[Python]代码

   1. from django.conf.urls.defaults import patterns,url  

#or use login_required  
from django.contrib.admin.views.decorators import staff_member_required  

def login_url(regex, view, *p,**args):  
    """ 
    urlpatterns = patterns('', 
    login_url(r'^$',direct_to_template, {'template': '1.html'}), 
    ) 
    """  
    return url(regex,staff_member_required(view),*p,**args)  

def login_patterns(*p):  
    """ 
    urlpatterns = login_patterns('', 
    (r'^$',direct_to_template,{'template':'1.html'}), 
    ) 
    """  
    d=[]  
    d.append(p[0])  
    for i in xrange(1,len(p)):  
    d.append(login_url(*p[i]))  
    return patterns(*d)  

标签:Django

收藏

0人收藏

支持

0

反对

0

发表评论