NoReverseMatch at / Reverse for 'add_time_slot' with arguments '('',)' not found. 1 pattern(s) tried: ['add_time_slot/(?P<turf_id>[0-9]+)/\\Z']

67 views
Skip to first unread message

Sudharsan

unread,
Nov 1, 2023, 2:42:41 PM11/1/23
to Django users
i getting an error while doing python django project. i was tried many things but nothing works. Please help me guys.
error.png
views.py
# view for adding Turf page
def add_Turf(request):
submitted = False
if request.method == "POST":
form = TurfForm(request.POST)
if form.is_valid():
var = form.save(commit=False)
var.created_by = request.user
var.save()
messages.info(request, ' Your Turf has added successfully')
turf_id=var.id
return redirect('add_time_slot',turf_id=turf_id)
else:
form = TurfForm
if 'submitted' in request.GET:
submitted = True
return render(request, 'addvenue.html',{'form': form, 'submitted': submitted})


# view for adding time slot

def add_time_slot(request,turf_id):
turf = Venue.objects.get(pk=turf_id)
if request.method == 'POST':
form = TimeSlotForm(request.POST)
if form.is_valid():
timeslot = form.save(commit=False)
timeslot.turf = turf # Set the Turf for this TimeSlot
timeslot.save()
return redirect('add_time_slot', turf_id=turf)
else:
form = TimeSlotForm()
return render(request, 'add_time_slot.html', {'form': form, 'turf': turf})



modelspy.pngmodelspy2.pngerror3.png










Migui Galan

unread,
Nov 1, 2023, 2:47:28 PM11/1/23
to django...@googlegroups.com
Hi! can you include the urls.py code? this is mainly because you have not included the <id> within the url setup

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/439756cf-9e61-430f-8d28-c72afb9b4a49n%40googlegroups.com.

Sudharsan

unread,
Nov 1, 2023, 2:52:49 PM11/1/23
to Django users
urlpatterns = [
path('', views.home, name ='home'),
path('home/', views.allTurfs,name = 'allturfs'),
path('profile/', views.dashboard, name = 'profile'),
path('about/', views.about, name = 'about'),
path('add_venue/', views.add_Turf, name = 'add_turf'),
path('<slug:slug_p>/', views.allTurfs, name='turf_by_place'),
path('<slug:slug_p>/<slug_t>', views.Turf_det, name='turf_det'),
path('add_time_slot/<int:turf_id>/', views.add_time_slot, name='add_time_slot'),
]

Adesewa Lola

unread,
Nov 1, 2023, 3:05:51 PM11/1/23
to django...@googlegroups.com
Hi Check your urls.py code

Sudharsan

unread,
Nov 1, 2023, 3:08:31 PM11/1/23
to Django users
urlpatterns = [
path('', views.home, name ='home'),
path('add_time_slot/<int:turf_id>/', views.add_time_slot, name='add_time_slot'),
]

Vincenzo Celano

unread,
Nov 1, 2023, 3:16:30 PM11/1/23
to django...@googlegroups.com
I think the problem is in the data into turf_id. Are you sure that turf_id contains only integer value? it's strange the problem with argument: '('',)' - try to verify the data passed with turf_id if are correct...

Sudharsan

unread,
Nov 1, 2023, 3:31:21 PM11/1/23
to Django users
i used turf_id from django default id column. my doubt is the django default id column isn't integer?

Migui Galan

unread,
Nov 1, 2023, 3:31:30 PM11/1/23
to django...@googlegroups.com
thank you! i think this is because you are not looping or have a turf_id in the template. by 'loop' or have you tried '/add_time_lot/<int:turf_id>/'?

Sudharsan

unread,
Nov 1, 2023, 3:43:25 PM11/1/23
to Django users
thank you for your replay. i tried  path('/add_time_slot/<int:turf_id>/', views.add_time_slot, name='add_time_slot'),
 but i getting the same error. when i  manually type  this /add_time_slot/1/  in the address bar i  get the page that's what i don't understand

Amen Guda

unread,
Nov 5, 2023, 4:54:41 PM11/5/23
to django...@googlegroups.com
To resolve this issue, you should check the place in your code where
the URL reversal with the name 'add_time_slot' is happening with an
empty argument (''). Ensure that the argument being passed to the URL
reversing function isn’t empty and correctly matches the URL pattern
specified in your URL configuration.


On Wed, Nov 1, 2023 at 5:41 PM Sudharsan <sudhar...@gmail.com> wrote:
>
> i getting an error while doing python django project. i was tried many things but nothing works. Please help me guys.
Reply all
Reply to author
Forward
0 new messages