S
S
sha2562019-12-19 07:27:13
Django
sha256, 2019-12-19 07:27:13

How to work with forms and POST requests in Django?

Friends, hello everyone!
I'm a beginner Dzhangovod, I'm trying to write a web client that should take data from a web form with a POST, forward it to an external server with a GET and return a response to the form.
Can you post an implementation example?
I have now gone along the path of creating the forms.py file in the application directory, but I can’t find anything other than examples with the CreateView method. I do not need to work with the database in this application.
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2019-12-19
@deepblack

POST to take data, forward it to the external server with GET and return the response to the form.
Can you post an implementation example?

View example:
class YouView(View):
    def post(self, request):
        you_data_1 = request.POST.get("youData1")
        you_data_2 = request.POST.get("youData2")
        you_data_3 = request.POST.get("youData3")

How to deal with requests I think it will be superfluous to explain.
For requests to external services, it would be better to use a message queue.

D
Dr. Bacon, 2019-12-19
@bacon

forward them to the external server with a GET and return a response to the form.

This is where you need an asynchronous framework like aiohttp and the like. And with Django, waiting for a response from an external server will block all other requests for you. Well, only if one user or a small number of them does not use this, but at very different times, then do not care.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question