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 https://docs.djangoproject.com/en/4.0/ref/csrf/ !!)

form.html

<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">
  </form>

views.py

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

    return render(request, 'testform.html')

urls.py

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