django use float in url

Solutions on MaxInterview for django use float in url by the best coders in the world

showing results for - "django use float in url"
Willard
03 May 2020
1from django.urls import path, register_converter
2class FloatConverter:
3    regex = '[\d\.\d]+'
4
5    def to_python(self, value):
6        return float(value)
7
8    def to_url(self, value):
9        return '{}'.format(value)
10        
11register_converter(FloatConverter, 'float')
12
13urlpatterns = [
14    path('admin/', admin.site.urls),
15    path('<float:float_number>/',TemplateView.as_view(template_name='homepage.html')), 
16]
17