When I click the button I always get the method GET instead of post: Any Ideas? Thanks!
<body>
<form action="/reset" type="POST">
{% csrf_token %}
<h3>Random Word (attempt # {{request.session.counter}})</h3>
<div>
<h1>{{request.session.rword}}</h1>
</div>
<label for="title">Title</label>
<input type="text" name="title" id="">
<button type="submit">Generate</button>
</form>
CodePudding user response:
The type of the request is specified with the method="…
attribute, so:
<form action="/reset" method="POST">
…
</form>
CodePudding user response:
<body>
<form action="/reset" method="POST">
{% csrf_token %}
<h3>Random Word (attempt # {{request.session.counter}})</h3>
<div>
<h1>{{request.session.rword}}</h1>
</div>
<label for="title">Title</label>
<input type="text" name="title" id="">
<button type="submit">Generate</button>
</form>
CodePudding user response:
due to the fact that you have used the type
attribute, rather than the method
attribute(which is the correct one), your code is not working. In order to change this, you must change the type
to method
. Also, for the action section of your form, I think it is better to use the Django url patterns, for example, {% url 'reset' %}
rather than writing /reset
.
<body>
<!-- So in this line, I changed the action, as well as the type to method, make sure to put the actual url pattern of the /reset page rather than what I put -->
<form action="{% url 'reset' %}" method="POST">
{% csrf_token %}
<h3>Random Word (attempt # {{request.session.counter}})</h3>
<div>
<h1>{{request.session.rword}}</h1>
</div>
<label for="title">Title</label>
<input type="text" name="title" id="">
<button type="submit">Generate</button>
</form>
<body>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>