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

@login_required is not defined #140

Open
omgitskuei opened this issue Nov 5, 2020 · 3 comments
Open

@login_required is not defined #140

omgitskuei opened this issue Nov 5, 2020 · 3 comments

Comments

@omgitskuei
Copy link

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
Copy link
Member

das-g commented Nov 5, 2020

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
Copy link
Author

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
Copy link
Member

das-g commented Nov 6, 2020

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

👍 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.

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