mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-30 18:09:59 +03:00
Allow suffix_require=None, only non-suffixed URL
In the current format_suffix_patterns, there are only two options 1) suffix_required=False: URL with both suffix and non-suffixed will be generated 2) suffix_required=True: Only URL with suffixed will be generated. There is no option for 3) suffix_required=None: Only URL with non-suffixed will be generated. By allowing suffix_required to None, we can achieve 3). This makes it cleaner when you use django rest swagger as you will not have duplicated endpoint one with suffix and the other without suffix from appearing.
This commit is contained in:
parent
dc6b3bf42e
commit
83f744350e
|
@ -77,7 +77,9 @@ def apply_suffix_patterns(urlpatterns, suffix_pattern, suffix_required, suffix_r
|
|||
else:
|
||||
new_pattern = url(regex, view, kwargs, name)
|
||||
|
||||
ret.append(new_pattern)
|
||||
# If suffix_required is None, we don't need suffix at all
|
||||
if suffix_required is not None:
|
||||
ret.append(new_pattern)
|
||||
|
||||
return ret
|
||||
|
||||
|
@ -93,6 +95,7 @@ def format_suffix_patterns(urlpatterns, suffix_required=False, allowed=None):
|
|||
suffix_required:
|
||||
If `True`, only suffixed URLs will be generated, and non-suffixed
|
||||
URLs will not be used. Defaults to `False`.
|
||||
If None, only non-suffixed URLs will be used.
|
||||
|
||||
allowed:
|
||||
An optional tuple/list of allowed suffixes. eg ['json', 'api']
|
||||
|
|
Loading…
Reference in New Issue
Block a user