本文实例讲述了Python中Django框架利用url来控制登录的方法。分享给大家供大家参考。具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
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) |
希望本文所述对大家的Python程序设计有所帮助。