Explore Courses Blog Tutorials Interview Questions

Explore Tech Questions and Answers

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

0 votes
by (19.9k points)

I am using two views in django: one for showing a form and get data and then use the data as an argument to the second view. But I could not quite figure this out as how to do it.

So far my views look like

class View1(View):

    def get(self, request):

        return render(request, 'example/view1.html')

class View2(View):

    def get(self, request, arg1):

        token = processData(arg1)

        context = {

            'word': token,


        return render(request, 'example/view2.html', context)

I have my set up as

app_name = example 

urlpatterns = [ 

    path('', View1.as_view(), name='view1'), 

    path('view2/', View2.as_view(), name='view2'), 


Now in the template view1.html I have the following code

<form action="{% url 'example:view2 expected_argument %}" method="get">

        {% csrf_token %}

        <input id="key" type="text" name="key">

        <input type="submit" value="Submit">


what would be the 'expected_argument' in the template so that I can get the input form value from the view1.html template, and then pass it on to the View2.

1 Answer

0 votes
by (25.1k points)

There is no "expected argument". Your view2 URL does not accept one, and it's not possible for a form to update its own URL like that anyway.

You don't need an argument there at all. Remove arg1 from the signature of that get method, and get your data inside that function via request.GET['key'].

Browse Categories