get:
<form action="/def_search_get" method="get">
{# action中填後臺對應的 get/post方法名#}
<input type="text" name="q">
<input type="submit" value="搜索">
</form>
post:
<form action="/def_search_post" method="post">
{% csrf_token %}
<input type="text" name="q">
<input type="submit" value="Submit">
</form>
其他路徑都一樣
報錯:RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you have APPEND_SLASH set. Django can’t redirect to the slash URL while maintaining POST data. Change your form to point to 127.0.0.1:8000/def_search_post/ (note the trailing slash), or set APPEND_SLASH=False in your Django settings.
辦法:form中給post方式的路徑末尾加/
即:
<form action="/def_search_post/" method="post">