from django.urls import path
app_name = 'main'
urlpatterns = [
path('someurl/<uuid:guid>/'), # guid must be None or some kind of value.
]
I need to get None or UUID value in my view
from django.urls import path
app_name = 'main'
urlpatterns = [
path('someurl/<uuid:guid>/'), # guid must be None or some kind of value.
]
I need to get None or UUID value in my view
you can make the UUID parameter optional directly in the URL pattern by including guid as a parameter that can be omitted:
from django.urls import path, re_path
from . import views
app_name = ‘main’
urlpatterns = [
path(‘someurl/’, views.your_view, name=‘without_guid’),
path(‘someurl/uuid:guid/’, views.your_view, name=‘with_guid’),
]
The view will receive guid as None if the URL is /someurl/, or it will receive a UUID if the URL is /someurl//.
I would suggest you probably want two very different views for this.
ahh. I am tired of this views.
Thanks for advice.