0

I need to verify the length of number grabbed from URL such as example.com/12345678 in django ?

urlpatterns = [
    path("", main.views.index, name="index"),
    path("admin/", admin.site.urls),
    path('<int:tnum>/', main.views.number, name="number")

And if the number doesn't match a certain length I want to output number is invalid.

Mian Imran
  • 11
  • 3

1 Answers1

0

This has already been answered here: How to find length of digits in an integer?

Essentially, you first convert the integer to a string and then get the length of the string.

So in your view, you will need to have some logic like this:

tnum_length = len(str(tnum))
brandonris1
  • 455
  • 3
  • 9
  • Thanks a lot for guiding me, actually after I post the question I did find the same question you mentioned. – Mian Imran Feb 05 '21 at 13:23