0

I am developing a web app and I want to use query parameter to show the task description. Currently I am using a post method which gets the ticked checkboxes and then redirects it to another view then that displays the description. Here is my code:

Here is my views.py:

@login_required
def view_task_description(request):
    if request.method == 'POST':
        task_description = GetTaskDescription(data=request.POST, user=request.user)
        if task_description.is_valid():
            obj = GetTaskDescription.get_task_description(task_description)
            return redirect('get_task_description', pk=obj[0].pk)
    return render(request, 'todoapp/select_task_description.html', context={'view_tasks': GetTaskDescription(user=request.user)})


@login_required
def get_task_description(request, pk):
    obj = get_object_or_404(Task, pk=pk)
    return render(request, 'todoapp/task_desc.html', context={'description': obj.description})

Here is my forms.py:

class GetTaskDescription(forms.Form):

    get_tasks = forms.ModelMultipleChoiceField(
        queryset=Task.objects.none(),
        widget=forms.CheckboxSelectMultiple,
        required=True
    )

    def __init__(self, *args, **kwargs):
        self.user = kwargs.pop('user')
        super(GetTaskDescription, self).__init__(*args, **kwargs)
        self.fields['get_tasks'].queryset = self.user.task_set.all()

    def get_task_description(self):
        tasks = self.cleaned_data['get_tasks']
        return tasks

Here is my urls:

url(r'^view_task_description/$', views.view_task_description, name='view_task_description'),
url(r'^view_task_description/(?P<pk>[0-9]+)/$', views.get_task_description, name="get_task_description"),

I want to display the task description simply using get and not the whole way around using post and then get. I am not able to figure that out. Kindly help me.

Vai
  • 343
  • 3
  • 17
  • Possible duplicate of [Capturing url parameters in request.GET](https://stackoverflow.com/questions/150505/capturing-url-parameters-in-request-get) – Flux Mar 13 '19 at 15:33

1 Answers1

0

You can always access the get parameters even in a POST request like this:

request.GET.get('param_name')
p14z
  • 1,760
  • 1
  • 11
  • 17