我遇到了一个看似简单的问题,但我还没有找到一种方法来调试它。
在我们的制作网站的管理员中,当编辑具有ForeignKey to User的对象时,所有用户都显示为 [email protected] 。这使得管理员在这些领域无法使用!
我尝试使用谷歌搜索问题,但由于“电子邮件受保护”一词出现在不相关的上下文中的许多邮件列表中,我找不到解决方案。此外,我在Django代码库中搜索“email protected”,但我没有找到它。
知道该怎么做?
答案 0 :(得分:22)
我真的不知道答案,但每当我看到 [email protected] 出现在Google上时,如果我导航到该链接,那么电子邮件会显示出来,如果我检查了该元素,靠近它这段javascript:
/* <![CDATA[ */
(function(){try{var s,a,i,j,r,c,l=document.getElementById("__cf_email__");a=l.className;if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
这可能对您有所帮助。 (检查你的元素,看看这是否适用于你。)
如果您在代码中也看到了这一点,那么This和this可能对您有帮助。
编辑:它似乎是由Cloudflare's email obfuscation引起的。
答案 1 :(得分:1)
电子邮件混淆对于公共网站来说是件好事,我想为管理员禁用它。所以我写这个中间件来禁用admin中的电子邮件混淆。
def _insert_email_off(html):
origin = html
try:
pos1 = html.index('>', html.index('<body')) + 1
html = html[:pos1] + '<!--email_off-->' + html[pos1:]
pos2 = html.index('</body>')
html = html[:pos2] +'<!--/email_off-->' + html[pos2:]
except ValueError:
return origin
return html
class CloudflareEmailProtect(MiddlewareMixin):
def process_response(self, request, response):
if request.path.startswith('/admin/'):
response.content = smart_bytes(_insert_email_off(smart_text(response.content)))
return response
class TestCloudflareEmailProtect:
def test_admin(self, rf):
request = rf.get('/admin/aaa')
html = '<html><body>content</body>'
response = CloudflareEmailProtect().process_response(request, HttpResponse(html))
assert b'<!--email_off--' in response.content
def test_not_admin(self, rf):
request = rf.get('/public')
html = '<html><body>content</body>'
response = CloudflareEmailProtect().process_response(request, HttpResponse(html))
assert b'<!--email_off--' not in response.content
def test_insert_email_off():
html = 'aa <body zzz>bb cc</body>dd'
result = _insert_email_off(html)
assert result == 'aa <body zzz><!--email_off-->bb cc<!--/email_off--></body>dd'
assert _insert_email_off('aaa') == 'aaa'
答案 2 :(得分:1)
我也面对这个问题,浪费了很多次解决方案。 最后,我只需添加即可解决此问题。
在HTML页面中添加
aws support describe-severity-levels
问题主要是针对“ Cloudflare混淆电子邮件”。
从dashbaord停用。
登录到Cloudflare仪表板。
确保已选择要验证的网站。
单击Scrape Shield应用程序。
在“电子邮件地址混淆”下,检查切换开关是否设置为“开”。