outdated django book

98 views
Skip to first unread message

knowledge_seeker

unread,
Apr 27, 2012, 10:09:32 PM4/27/12
to Django users
My Django book (from the university library) said to add the label
"@login_required" to views that I wish to restrict user access on.
Django 1.4 does not allow this; obviously the book is dated! Is there
a more modern way to get the same effect?

Similarly, admin does not allow access to my classes, even when I have
created an Admin class; is this a new security feature?

Finally, when I tried to create a view that allowed web-based user
creation, the views.py file would not recognize the class "User"; is
there something I need to import?

Jonathan D. Baker

unread,
Apr 27, 2012, 10:30:26 PM4/27/12
to django...@googlegroups.com, Django users
You need to import User from django.contrib.auth.models and login_required from django.contrib.auth.decorators. Hope this helps.

Sent from my iPhone
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>

Daniel Roseman

unread,
Apr 28, 2012, 4:14:59 AM4/28/12
to django...@googlegroups.com
Which, of course, is nothing to do with Django versions, and was true even when the Django book was new.


On Saturday, 28 April 2012 03:30:26 UTC+1, jondbaker wrote:
You need to import User from django.contrib.auth.models and login_required from django.contrib.auth.decorators. Hope this helps.

Sent from my iPhone

Jonathan Baker

unread,
Apr 28, 2012, 2:13:16 PM4/28/12
to django...@googlegroups.com
Ah yes, I should have clarified that in my response. @knowledge_seeker, if you'll check your python code with a tool like pyflakes it will tell you when you're referencing modules that have not been imported (as well as many other common errors). I use the pyflakes for vim plugin and it saves me from a ton of headaches.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/6ExeXS4aUn8J.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
Jonathan D. Baker
Developer
http://jonathandbaker.com

knowledge_seeker

unread,
Apr 29, 2012, 3:24:48 PM4/29/12
to django...@googlegroups.com
Thanks for the help guys; I am glad the books were not so out of date!

Reinout van Rees

unread,
Apr 29, 2012, 4:59:51 PM4/29/12
to django...@googlegroups.com
On 29-04-12 21:24, knowledge_seeker wrote:
> On Friday, April 27, 2012 7:09:32 PM UTC-7, knowledge_seeker wrote:
>
> My Django book (from the university library) said to add the label
> "@login_required" to views that I wish to restrict user access on.
> Django 1.4 does not allow this; obviously the book is dated! Is there
> a more modern way to get the same effect?

Perhaps your @login_required error was also an forgot-to-import-it
error. But it also might be because you're using a class based view.

If so, look for the 'decorators' heading in the following link:
http://www.caktusgroup.com/blog/2011/12/29/class-based-views-django-13/

You need to decorate the dispatch() method in the class-based-view case.


Reinout

--
Reinout van Rees http://reinout.vanrees.org/
rei...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

Reply all
Reply to author
Forward
0 new messages