I want to use REST to populate a fobi form

I have created a form with Django Fobi that I want to populate with REST.

I can view and enter data in the app at

http://localhost:8000/fobi/view/dose-results/

I have not found a good example of using REST to POST to a Fobi form. That is probably all I need, an example.

Thanks

You don’t POST to a form.

You POST to a view. And, when the view is coded to do so, the view will take the POST data and use it to populate a form.

If you submit the POST data in an HTML POST format, then your view can work with it as if the data were submitted from the browser.
(Also see Sending form data - Learn web development | MDN)

Or, you could submit the data as JSON, and have a view that binds the form to a dict submitted in the body of the request. (See The Forms API | Django documentation | Django)

Ok did some experimenting.

I created a fobi form and submitted it and found the following:

    requestcookies = request.COOKIES
    print('requestcookies = ', requestcookies)

yields this in the terminal

requestcookies =  {'csrftoken': 'm9aKiw0Wj0EgFQhDy0HMZnehjLLPHIsN'}

and

        mybody = request.body.decode('utf-8')
        print("mybody=", mybody)

yields this in the terminal

mybody= ------WebKitFormBoundaryrBd3iJBq4j6AQStQ
Content-Disposition: form-data; name=“csrfmiddlewaretoken”

nDxndjsRR019VXmJy8w1AKFLXV8W5LHsyaeUTdfluwUfEOYJpd5KqefW75GNh7cn
------WebKitFormBoundaryrBd3iJBq4j6AQStQ
Content-Disposition: form-data; name=“param1”

Hello8
------WebKitFormBoundaryrBd3iJBq4j6AQStQ
Content-Disposition: form-data; name=“param2”

World from postman8
------WebKitFormBoundaryrBd3iJBq4j6AQStQ
Content-Disposition: form-data; name=“description”

Now is the time postman
------WebKitFormBoundaryrBd3iJBq4j6AQStQ
Content-Disposition: form-data; name=“notify”

mo@gmail.com
------WebKitFormBoundaryrBd3iJBq4j6AQStQ–

So I did a Postman series to the same URL with a POST with the same headers and body. The csrf cookie is there and presented and the embedded csrfmiddlewaretoken are identical. Yet get a 403 error with CSRF token missing.

There are many different CSRF errors that can be thrown that all fit into the general category of “CSRF token missing”. You need to read the complete error message generated to help identify exactly what has gone wrong.

Its ok, I am using DRF PUT to populate my Fobi form now and not trying to duplicate the POST that was throwing the CSRF error.