Created
March 31, 2016 04:55
-
-
Save tag1216/857d23dbf62ff0655117a18e88e90a50 to your computer and use it in GitHub Desktop.
djangoでurls.pyにデコレータを書く
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def decorate(view_func, decorators): | |
""" | |
Viewをデコレータでラップする。 | |
@param view_func: | |
@param decorators: | |
@return: | |
""" | |
if decorators: | |
for decorator in reversed(decorators): | |
view_func = decorator(view_func) | |
return view_func | |
# 未ログインでもアクセス可能 | |
PUBLIC = [] | |
# ログインユーザーのみアクセス可能 | |
AUTHENTICATED = [ | |
login_required, | |
] | |
urlpatterns = [ | |
url(r'^$', decorete(views.IndexView.as_view(), PUBLIC), name='index''), | |
url(r'home/^$', decorete(views.HomeView.as_view(), AUTHENTICATED), name='home'') | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment