django get和post报错

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">

猜你喜欢

转载自blog.csdn.net/zhanshendiaq/article/details/81635967