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

{% csrf_token %} not available inside component HTML #12

Closed
Buroni opened this issue Oct 14, 2020 · 4 comments
Closed

{% csrf_token %} not available inside component HTML #12

Buroni opened this issue Oct 14, 2020 · 4 comments

Comments

@Buroni
Copy link

Buroni commented Oct 14, 2020

Firstly thanks for creating this useful library.

I've noticed that {% csrf_token %} isn't rendered when used inside component template HTML. Other default Django template tags seem to work, so I'm guessing this is because the component HTML doesn't have access to Django's RequestContext.

A work-around is to just pass down the {% csrf_token %} inside a slot from the parent component, however this becomes repetitive. I'm wondering if it's currently possible to give the component access to the necessary context. Cheers!

@EmilStenstrom
Copy link
Owner

Excellent question, this is something I have totally missed. I'll have a look and see if I can find a way to propagate the requestcontext down into a component, I think that is what people would expect.

I have lots of other things going on, but I'll see if I can find some time during the weekend. A PR would be appreciated though :)

@Buroni
Copy link
Author

Buroni commented Oct 15, 2020

Thanks @EmilStenstrom I'll try to dig into the library a bit at the end of the week.

@EmilStenstrom
Copy link
Owner

I have looked at this for a couple of hours with no luck. The problem is that I can't manage to get a good testcase going. There are sooo many moving parts involved with csrf, and most current tests are at the unit test level. If you have the time and know how to create a failing test for csrf_token, please help me out!

@EmilStenstrom
Copy link
Owner

@Buroni I just released django-reusable-components 0.5 to pypi, in which @rbeard0330 reworked context handling. Would you mind trying to call csrf_token inside a component again to see of things work now?

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