我在Odoo v 10中遇到联系表单时出现错误,当我按下发送按钮时会出现异常:
追踪(最近的呼叫最后):
_dispatch中的文件“/usr/lib/python2.7/dist-packages/odoo/addons/base/ir/ir_http.py”,第195行 result = request.dispatch()
发送文件“/usr/lib/python2.7/dist-packages/odoo/http.py”,第823行 raise werkzeug.exceptions.BadRequest('Session expired(无效的CSRF令牌)')
BadRequest:400:错误请求
如果我添加代码以将Github问题中建议的CSRF令牌加载到表单中:
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
它会引导我显示一个显示单词false
的新空白页面。
在“网页布局”中,我有下一个javascript代码:
<script type="text/javascript">
var odoo = {
csrf_token: "<t t-esc="request.csrf_token(None)"/>",
};
</script>
我不知道此代码是否是手动添加的,或者默认情况下是否附带了Odoo,因为这是一个继承的安装。
“与我们联系”块配置了Send an Email
操作和有效Recipient email
,Thank You Page
有效。
这是添加块后的最终代码(没有CSRF隐藏输入):
<section class="as-contact-us" style="background-image: url(/theme_laze/static/src/img/our-work.jpg)">
<div class="container">
... Company description elements ...
<div class="col-md-8">
<form action="/website_form/crm.lead" method="post" data-model_name="mail.mail" data-success_page="/page/website_crm.contactus_thanks" class="s_website_form form-horizontal container-fluid mt32" enctype="multipart/form-data">
<div class="ascu-form">
<div class="row">
<div class="col-md-6">
<input class="form-control o_website_form_input" name="contact_name" required="" placeholder="Your Name*" type="text"/>
</div>
<div class="col-md-6">
<input class="form-control o_website_form_input" name="email_from" required="" placeholder="Your Email*" type="text"/>
</div>
</div>
<div class="row">
<div class="col-md-12">
<textarea class="form-control o_website_form_input" name="description" required="" placeholder="Message*"/>
</div>
<div class="col-md-12">
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
<button class="creative-btn1 o_default_snippet_text">Send</button>
</div>
</div>
</div>
<input class="form-field" name="email_to" value="to@email.org" type="hidden"/>
</form>
</div>
... Div closures ...
</div>
</section>
有人知道问题在哪里吗?
我不想停用CSRF保护。
答案 0 :(得分:0)
我不是路由问题!请参见下面的代码“ csrf = False”并插入以解决问题。
class ZipFileGenerator
# Initialize with the directory to zip and the location of the output archive.
def initialize(input_dir, output_file)
@input_dir = input_dir
@output_file = output_file
end
# Zip the input directory.
def write
entries = Dir.entries(@input_dir) - %w(. ..)
::Zip::File.open(@output_file, ::Zip::File::CREATE) do |io|
write_entries entries, '', io
end
end
private
# A helper method to make the recursion work.
def write_entries(entries, path, io)
entries.each do |e|
zip_file_path = path == '' ? e : File.join(path, e)
disk_file_path = File.join(@input_dir, zip_file_path)
puts "Deflating #{disk_file_path}"
if File.directory? disk_file_path
recursively_deflate_directory(disk_file_path, io, zip_file_path)
else
put_into_archive(disk_file_path, io, zip_file_path)
end
end
end
def recursively_deflate_directory(disk_file_path, io, zip_file_path)
io.mkdir zip_file_path
subdir = Dir.entries(disk_file_path) - %w(. ..)
write_entries subdir, zip_file_path, io
end
def put_into_archive(disk_file_path, io, zip_file_path)
io.get_output_stream(zip_file_path) do |f|
f.puts(File.open(disk_file_path, 'rb').read)
end
end
end
答案 1 :(得分:0)
我面临着同样的问题,只是启用了Chrome中的cookie即可解决我的问题。
使用启用Cookie。
1)单击chrome设置
enter image description here
2)点击高级>>隐私和安全
enter image description here
3)点击网站设置
enter image description here
4)单击Cookie和站点数据
enter image description here
5)启用给定。
enter image description here
答案 2 :(得分:0)