Converters
Converters are used within URL definitions of Django. They can be used to add additional custom path components to URLs.
New converter classes will be automatically added when Django loads the defined URLs.To create a new string-based converter, just follow a simple structure and add the code to the specified file.
# [...]
class MyIDConverter(StringConverter):
regex = r"some-value-\d{4}"
# [...]
In URL definitions we can access this newly defined converter by using its class name:
urlpatterns = [
# The name must be lower-case and without 'converter' at the end
path("/some/path/<myid:pk>", MyModelView.as_view(), name=...),
]
The following default converters will be registered on application start:
Class |
URL name |
Regex |
---|---|---|
|
findingtemplateid |
|
|
vulnerabilityid |
|
|
findingid |
|
|
md5 |
|
|
hostid |
|
|
componentid |
|
|
dependencyid |
|