create a dynamic action url form in django python

you can try it with a redirect: (and think about using a CSRF Token and enable CsrfViewMiddleware … see django docs !!)


<form method="POST">

    {% csrf_token %}    

    <label for="fname">First Name</label>
    <input type="text" id="fname" name="firstname" placeholder="Your name..">

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

def testform(request):
    if request.method == 'POST':
       fname = request.POST.get('firstname')
       return redirect('testformresult', student=fname)

    return render(request, 'testform.html')

path('testform', views.testform, name='testform'),
path('student/testformresult/<slug:student>', views.testformresult, name='testformresult'),

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top