D
D
Dizzy Qucile2020-11-06 23:01:23
Django
Dizzy Qucile, 2020-11-06 23:01:23

How to get text from POST request?

I'm sorry for such a stupid question
. There is a layout:

...
<form action="" method="POST">
    {% csrf_token %}
    <input type="text">
    <input type="submit" name="city">
</form>
...


And I'm trying to get the value that was entered in the input text in views.py
def home(request):
    print(request.POST)
    ...


But this is the result:
<QueryDict: {'csrfmiddlewaretoken': ['DRd1em12YAXIGFY2Fdp26vfqcrgip5VyOvSWJPGIDOEAaT3vb4AM5eAXcLnzUKSO'], 'city': ['Submit']}>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dizzi Qucile, 2020-11-07
@DiZiNnEs

The error was due to two inputs, I changed the layout to this one and it worked:

<form action="" method="POST">
    {% csrf_token %}
    <input type="text" name="city">
    <button type="submit">Submit</button>
</form>

S
soremix, 2020-11-06
@soremix

https://docs.djangoproject.com/en/dev/ref/request-...
Same .get as for regular dictionary.
request.POST.get('city')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question