Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Henrik ChristensenPython Web Development Techdegree Student 38,322 Points
I've been trying to make the PermissionRequiredMixin to redirect the user to a specific page if they don't have permission to view that page.
I struggled a lot making it redirect as I wanted it to because it kept redirecting to the login page (default), but now I finally made it redirect as I want it to.
Now I'm wondering if this is an okay way to do it, or if I should do it differently?
class NewsCreateView(LoginRequiredMixin, PermissionRequiredMixin, generic.CreateView): permission_required = 'news.can_add' fields = ('title', 'content', 'public', 'author') model = News def handle_no_permission(self): return HttpResponseRedirect(reverse('news:news'))