首页 > 解决方案 > 登录 Django 时如何发送一些按钮值?

问题描述

我有一个问题,我想在登录时提交并进一步传递按钮(Some_value)的值。

如果没有在表单中使用 csrf,调试模式建议我使用 csrf_token,当我这样做时 - 就像在下面的代码中一样,它给了我HTTP ERROR 405

在 HTML 中

        <td align="right">
            <form action="reg_this" method="post">
                {% csrf_token %}
                <button name="team_reg" value="Some_value">send this</button>
            </form>

在views.py

class Confirmation(BaseView):
    template_name = "my_page.html"

    @csrf_exempt
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        print(context)
        return context

在 urls.py

 url('^app/reg_this', views.Confirmation.as_view(template_name="my_page.html")),

我究竟做错了什么?

谢谢你的回答。

标签: pythondjangocsrf

解决方案


尝试使用按钮类型属性并将其值作为提交

<button name="team_reg" value="Some_value" type="submit">send this</button>

推荐阅读