-
-
Notifications
You must be signed in to change notification settings - Fork 953
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
Add custom URL convertor register #1437
Conversation
tests/test_convertors.py
Outdated
@@ -0,0 +1,99 @@ | |||
import datetime as dt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created multiple convertors here with the purpose of reproducing #1398. I can also simplify the test suite if wanted. Just let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with simplifying the tests, as this can be extended for other things like UUID
and there's not really much difference. This is really good.
Well this is nice and simple isn't it? Seems worthwhile. |
Custom URL Convertor
Currently, we don't have a way to create URL convertors, meaning that our users can only match the default types. Those are:
starlette/starlette/convertors.py
Lines 75 to 81 in 2b54f42
To be fair, there's a way: adding a
key, value
pair on theCONVERTOR_TYPES
dictionary. That's not available on Starlette's public API, or documented.The idea of this PR is to document and introduce a public API that can be used to create custom URL convertors.
How does Django and Flask handle this?
Both of them have a way to register custom URL convertors. You can find the way Django makes it possible here, and for Flask here.
Other
Recently, there was a PR to introduce time related convertors on #1398, and I think we should follow the path this PR proposes here, and not creating more convertors on Starlette itself.
Missing