开发者

admin only areas in django + app engine

i am using django-norel for deploying to app engine.what which one would be a better solution for admin only areas ? 1) using app.yaml to define admin only areas 2) writing a middleware for google userservice

update : there is this entry

   - url: /.*
  script: djangoappengine/main/mai开发者_如何学Gon.py

in ap.yaml doesn't that mean that all pages will be handled by main.py in case i am using login:admin how would that affect the current functionality?


Use app.yaml for admin areas because login: admin is an easy and clean solution.

If you want moderator functionality on public pages you can use users.is_current_user_admin().

Update: You can't use login: admin to restrict access to some functions in one file. If you want to use it you have to create a separate admin.py file or something.

You could also try to create a function decorator like @admin_required. Here's an example for @login_required.

Here's the part that you'd have to change:

user = users.get_current_user()
if not user:
   self.redirect(users.create_login_url(self.request.uri))
   return
else:
   handler_method(self, *args)

to

if not users.is_current_user_admin():
    self.redirect(denied_url)
    return
else:
    handler_method(self, *args)


For a third-party admin area I use appengine_admin. To pass the variable whether current user is admin to the template I also found the following convenient

self.response.out.write(template.render(path, {''admin':users.is_current_user_admin()..

then in template admin parts display towards admin with tag

{% if admin %} ... admin stuff
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜