Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't support django generic views? #38

Open
ceng-p opened this issue Sep 30, 2024 · 1 comment
Open

Doesn't support django generic views? #38

ceng-p opened this issue Sep 30, 2024 · 1 comment

Comments

@ceng-p
Copy link

ceng-p commented Sep 30, 2024

Docs state to use @settings.AUTH.login_required how would this be used in generic views?

@settings.AUTH.login_required
class `IndexView(generic.ListView):
...

I would also like to add the route to all views, is there a generic way to do this other than adding the decorator everywhere?

@rayluo
Copy link
Owner

rayluo commented Oct 20, 2024

Docs state to use @settings.AUTH.login_required how would this be used in generic views?

@settings.AUTH.login_required class `IndexView(generic.ListView): ...

I haven't tried that myself. You may try to see whether Decorating class-based views helps.

I would also like to add the route to all views, is there a generic way to do this other than adding the decorator everywhere?

This library does not provide such a way out of the box, but perhaps you can look into How to apply a decorator to all views (of a module) in django.

Caveat: Only decorate the views that really need authentication, rather than blindly decorate ALL requests. There used to be a troubleshooting case where the reporter managed to incorrectly decorate both /index and /images/logo.jpg. The latter was also used in their login template`. That setup ended up having their login page triggered another login session which caused the original login session to always fail. It was difficult to debug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants