user7613100
user7613100

Reputation:

Retrieving information from a POST without forms in Django

I'm developing something like an API (more like a communications server? Idk what to call it!) to receive data from a POST message from an external app. Basically this other app will encounter an error, then it sends an error ID in a post message to my API, then I send off an email to the affected account.

My question is how do I handle this in Django without any form of UI or forms? I want this to pretty much be done quietly in the background. At most a confirmation screen that the email is sent.

I'm using a LAMP stack with Python/Django instead of PHP.

Upvotes: 0

Views: 706

Answers (1)

nigel222
nigel222

Reputation: 8222

A Django view doesn't have to use a form. Everything that was POSTed is there in request.POST which you may access directly. (I commonly do this to see which of multiple submit buttons was clicked).

Forms are a good framework for validating the data that was POSTed, but you don't have to use their abilities to generate content for rendering. If the data is validated in the front-end, you can use the form validation framework to check against front-end coding errors and malicious POSTs not from your web page, and simply process the cleaned_data if form.is_valid() and do "Something went wrong" if it didn't (which you believe to be impossible, modulo front-end bugs or malice).

Upvotes: 2

Related Questions