1👍
1) The urlmapper does by default not care about GET or POST request method. It will route any request to the given view-function.
Normally, your form html-code will look like this:
<form method="post" action="some_url">
...
</form>
So, when you submit the form, the data will be send to some_url with the specified method, in this case post.
You may want to read something about when to use GET or POST, normally forms are transferred using POST.
2) form = CategoryForm(request.POST)
will bind the values provided in the request’s POST-dictionary to the form. You may say, it prepopulates this. This way, further working with the form (like validating it by calling form.is_valid()
) will be made possible.
Perhaps you should investigate further on Django forms and modelforms by reading some official documentation.
0👍
Why do you think the URL mapper knows if it’s a post it a get? It doesn’t, and it doesn’t care.
The thing you are missing is that this view has two responsibilities: showing the initial form (on GET) and processing the submitted form (on POST).
Your second question shows an unfamiliarity with basic Python syntax. request.POST
is the parameter to the initialisation of the form instance.