question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to add decorators to the serve method

See original GitHub issue

At the moment, there is no way to add decorators to the serve method.

For example, we can’t add the csrf_exempt decorator. It may be useful for form pages with captcha (because there is no need in csrf token).

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
gasmancommented, Oct 26, 2022

Thanks @thenewguy! This looks good to me - a simple, backwards-compatible change that will allow people to solve this problem, and it doesn’t preclude building a more out-of-the-box solution in future that respects the CSRF flag without the need for a custom middleware, if there’s a desire for that.

So, in terms of the change to be made to Wagtail itself, this would just involve building, documenting and testing the find_page_for_request helper - nothing about that needs to indicate that it’s intended for use in middleware / CSRF handling. (If you were to subsequently write up a recipe detailing how to use this for CSRF control, I’d sure that would be welcomed, but probably out of scope for the main Wagtail docs and a better fit for a blog post or similar.) For the tests, we’d just need to validate that find_page_for_request returns the right result and that assertNumQueries gives 0 for any calls after the initial one.

0reactions
thenewguycommented, Oct 20, 2022

@zerolab @gasman This is the issue/solution I was referring to. Do you like it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Create and Use Decorators in Python With Examples
In this article I will show you how to create and use decorators. You will see how easy it is to use this...
Read more >
Documentation - Decorators - TypeScript
Decorators provide a way to add both annotations and a meta-programming syntax for class declarations and members. Decorators are a stage 2 proposal...
Read more >
Decorators and forwarding, call/apply
Decorators can be seen as “features” or “aspects” that can be added to a function. We can add one or add many. And...
Read more >
Modify a method using TypeScript decorators | Create & Code
We want to use the decorator for multiple service methods, so we need to be able to specify a unique cache key each...
Read more >
Attaching new behaviors through decorators in JavaScript
Decorator is a function that gives the ability to dynamically modify the existing functionality: by higher-order functions in the functional ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found