0

I have small problem with redirecting from one view to another according to Django topic.

Already read some answers like: ans_1, ans_2, ans_3, but can't find solution.

Instead get an error:

Reverse for 'add_tasks_continue' not found. 'add_tasks_continue' is not a valid view function or pattern name.

Goal: redirect from one view to another with some data.

My view functions:

def add_day_tasks(request):
    users = User.objects.all()
    if request.method == "POST":
        ...
        return redirect('add_tasks_continue', data=locals())

def add_tasks_continue(request, data):
    ...
    return render(request, 'eventscalendar/add_task_continue.html', locals())

My url:

app_name = 'calendar'
urlpatterns = [
    url(r'^$', calendar),
    url(r'^calendar/add_day_task/$', add_day_tasks),
    url(r'^calendar/add_task_continue/$', add_tasks_continue, name='add_tasks_continue'),
]

Thank you all for your time

Zaraki Kenpachi
  • 5,510
  • 2
  • 15
  • 38
  • Why do you pass `data`? Your URL does not expect that. (And in future please state exactly what problem you are having, target than "can't find solution".) – Daniel Roseman Aug 28 '19 at 07:50
  • @DanielRoseman the data is a dictionary [description updated]. With this method i need still pass regex patterns into url? – Zaraki Kenpachi Aug 28 '19 at 07:54
  • @ZarakiKenpachi: there is no builtin path converter for a dictionary, and likely there will not be one in the (near) future. URLs are not a good way to transfer such amounts of data. – Willem Van Onsem Aug 28 '19 at 07:57
  • @WillemVanOnsem the how to transfer data from one view to another? – Zaraki Kenpachi Aug 28 '19 at 07:58
  • @ZarakiKenpachi: you usually do not do that. Usually urls and GET and POST data are used to transfer *small* amounts of (usually scalar) data. Items that need to persist are stored in a database. Using `locals()` is by the way not a good idea either: how would you transfer a generic object? – Willem Van Onsem Aug 28 '19 at 08:01
  • @WillemVanOnsem yep you right i get brain lag :P – Zaraki Kenpachi Aug 28 '19 at 08:04

1 Answers1

0

Since add_tasks_continue(request, data) has a parameter "data", (?P<data>…) is expected in your url. That is the point. It could be url(r'^calendar/add_task_continue/(?P<data>[a-z]+)$', add_tasks_continue, name='add_tasks_continue') or else url(r'^calendar/add_task_continue/(?P<data>\d+)$', add_tasks_continue, name='add_tasks_continue'). However, you should keep in mind that url are strings, so "data" is supposed to be a string as it appears in the url.

jpaul
  • 309
  • 1
  • 5