DjangoGirls / tutorial-extensions

Additional tasks for tutorial
https://tutorial-extensions.djangogirls.org
Other
162 stars 202 forks source link

@login_required is not defined #140

Open omgitskuei opened 3 years ago

omgitskuei commented 3 years ago

Hi, after I add @login_required to functions comment_approve and comment_remove in views.py, I'm getting nameError in the CMD saying "login_required" is not defined.

das-g commented 3 years ago

Hi @omgitskuei

As explained in tutorial extension Homework: Adding security to your website, section Authorizing add/edit of posts, you'll have to import that decorator with

from django.contrib.auth.decorators import login_required

Put that import ... line in the top section of each Python file, in which you want to use the @login_required decorator.

Does the error still occur if you do that?

omgitskuei commented 3 years ago

Hi Django Girls, thank you this fixes the NameError. It would be helpful to have this import instruction in the Add Approve/Delete Comments section of your Extensions book. The sections didn't look like they needed to be read in order.

das-g commented 3 years ago

It would be helpful to have this import instruction in the Add Approve/Delete Comments section of your Extensions book.

:+1: Good point.

The sections didn't look like they needed to be read in order.

AFAIK, they indeed aren't intended to have to be read in order.

Can you make a pull request with that addition? You can find the source file for that section in this repository here at en/homework_create_more_models.