python - 登录 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")),
我究竟做错了什么?
谢谢你的回答。
解决方案
尝试使用按钮类型属性并将其值作为提交
<button name="team_reg" value="Some_value" type="submit">send this</button>
推荐阅读
- c++ - 在 Qt3D 中进行碰撞检测的预期方法(或好方法)是什么?
- sql-server - 通过 HTTPS 从 SQL Server 存储过程调用的 WCF 服务
- amazon-web-services - Amazon Redshift - 加入表并找出不匹配的行
- java - java.lang.IllegalStateException: org.hibernate.TransientObjectException(更新记录时)
- r - 无法在 R 中创建具有动态名称的非反应性 RenderPlot 对象
- android - 如何设置灯光弹出主题?
- javascript - 使用 Firebase 数据库规则禁用特定子项的写入
- postgresql - 使用 psycopg2 使用 ACCESS EXCLUSIVE 锁定表
- azure - MS Azure:无法将 Azure 云文件复制到另一个目录
- hyperledger-fabric - Hyperledger Composer - 错误 8:RESOURCE_EXHAUSTED