login-required

Django @login_required views still show when users are logged out by going back in history on Chrome

淺唱寂寞╮ 提交于 2019-12-04 15:47:15
问题 ::Edit:: @cache_control(no_cache=True, must_revalidate=True, no_store=True) FTW!!!!! Cache-Control: no-cache, no-store, must-revalidate did the trick. It took going to a few IRC chans and looking around but finally I got it to work. ::EDIT:: I have a view where I'm setting @login_required on it and its secure for the most part, but if you have looked at the view then logout and just hit the back button in your browser you can view the content again with out being asked to login. Though if you

Django: re-use login_required decorator inside other decorators

萝らか妹 提交于 2019-12-04 06:18:49
According to one of the comments in https://stackoverflow.com/a/8715790/210481 , which I agree with, we should avoid multiple decorators if one depends on the other. So, in the example, if we have a decorator "active_required" for active users, we should not have to use both active_required and login_required on the same view. We should have "login_required" decorator "called" somehow inside the "active_required" one. Is it possible to do it with the standard "login_required" decorator that comes with django? My requirements are: 1) if the user is not authenticated, I should redirect him to

Why do I need to decorate login_required decorator with @method_decorator

雨燕双飞 提交于 2019-12-03 01:11:44
I am trying to understand the code for the mixins posted at this blog post . These mixins call the login_required decorator from django.contrib.auth.decorators within the mixins , but they do so decorated by the method_decorator from django.utils.decorators . In the sample code below I dont understand why I need to decorate the login_required decorator . from django.utils.decorators import method_decorator from django.contrib.auth.decorators import login_required class LoginRequiredMixin(object): """ View mixin which verifies that the user has authenticated. NOTE: This should be the left-most

@login_required trouble in flask app

感情迁移 提交于 2019-12-01 16:08:46
I have created a blueprint that handles authenticating. This blue print uses Flask-Login. And has the following, as well as more code not shown. In the blueprint I have the following: from flask.ext.login import LoginManager from flask.ext.login import UserMixin from flask.ext.login import current_user from flask.ext.login import login_required from flask.ext.login import login_user from flask.ext.login import logout_user auth_print = Blueprint('auth_print', __name__) login_manager = LoginManager() login_manager.login_view = '/login' class User(UserMixin): user_store = {} # Stores the users

Check if a function has a decorator

為{幸葍}努か 提交于 2019-11-30 02:11:38
问题 My question is a general one, but specifically my application is the login_required decorator for Django. I'm curious if there is a way to check if a view/function has a specific decorator (in this case the login_required decorator) I am redirecting after logging a user out, and I want to redirect to the main page if the page they are currently on has the login_required decorator. My searches have yielded no results so far. 回答1: Build your own login_required decorator and have it mark the

Django: How can I apply the login_required decorator to my entire site (excluding static media)?

泄露秘密 提交于 2019-11-29 23:03:58
The example provides a snippet for an application level view, but what if I have lots of different (and some non-application) entries in my "urls.py" file, including templates? How can I apply this login_required decorator to each of them? (r'^foo/(?P<slug>[-\w]+)/$', 'bugs.views.bug_detail'), (r'^$', 'django.views.generic.simple.direct_to_template', {'template':'homepage.html'}), Dropped this into a middleware.py file in my project root (taken from http://onecreativeblog.com/post/59051248/django-login-required-middleware ) from django.http import HttpResponseRedirect from django.conf import