Answers for "django use float in url"

0

django use float in url

from django.urls import path, register_converter
class FloatConverter:
    regex = '[\d\.\d]+'

    def to_python(self, value):
        return float(value)

    def to_url(self, value):
        return '{}'.format(value)
        
register_converter(FloatConverter, 'float')

urlpatterns = [
    path('admin/', admin.site.urls),
    path('<float:float_number>/',TemplateView.as_view(template_name='homepage.html')), 
]
Posted by: Guest on August-26-2021

Python Answers by Framework

Browse Popular Code Answers by Language