How to process basic text input

  1. I want to have a template with a text input and a submit button
  2. When I press submit I want to process that text with a python function
  3. Finally, when the function process the text I want to redirect to another page

This is my code, there’s too many stuff going on for me because i’m new, can you tell me if it’s right?


<form action="{% url 'app.process_text' %}" method="post">
  {% csrf_token %}
  <input type="text">
  <input type="submit" value="Submit">

from django.urls import path
from . import views
from .views import ProcessText

urlpatterns = [
  path('projects/process_text', views.ProcessText, name='app_process_text'),

def ProcessText(request):
    # here im suposed to have a variable with the input to work with
    return render(request, 'app/just_another_page.html')

Thanks in advance!

Review Working with Forms.

You’ll want to create a Form class for your form. (Yes, it’s only one field, but it’s best to learn the right way from the beginning.)

You’ll also want to create a template for that form.

Your view will then process that form. On a successful post, you’ll then redirect to your target page. (See the example in that section of the docs.)

If you haven’t done so already, I strongly encourage you to work your way through either (or both) of the official Django Tutorial or the Django Girls Tutorial.

Thanks, I was needing that kind of direction