django makes it easy to restrict access to certain pages to logged-in users through the @login_required decorator decorator is directive placed just before function definition that python applies to the function before it runs to alter how the function code behaves let' look at an example restricting access to the topics page each topic will be owned by userso only registered users should be able to request the topics page add the following code to learning_logs/views pyviews py --snip-from django core urlresolvers import reverse from django contrib auth decorators import login_required from models import topicentry --snip-@login_required def topics(request)"""show all topics ""--snip-we first import the login_required(function we apply login_required(as decorator to the topics(view function by prepending login_required with the symbol so python knows to run the code in login_required(before the code in topics(the code in login_required(checks to see if user is logged inand django will run the code in topics(only if they are if the user is not logged inthey're redirected to the login page to make this redirect workwe need to modify settings py so django knows where to find the login page add the following at the very end of settings pysettings py ""django settings for learning_log project --snip-my settings login_url '/users/login/now when an unauthenticated user requests page protected by the @login_required decoratordjango will send the user to the url defined by login_url in settings py you can test this setting by logging out of any user accounts and going to the home page nextclick the topics linkwhich should redirect you to the login page then log in to any of your accountsand from the home page click the topics link again you should be able to reach the topics page user accounts