javascript Disqus 评论无法在本地主机上加载?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9475821/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disqus comments fails to load on localhost?
提问by rhodee
I would like to use the universal code and have ran into difficulties getting the most basic functionality done.
我想使用通用代码,但在完成最基本的功能时遇到了困难。
I would like to create a shortname for testand one for my deployment, which I did from the Disqus admin panel.
我想为测试创建一个短名称,为我的部署创建一个短名称,这是我在 Disqus 管理面板中所做的。
Here is the disqus code in my show action:
这是我的表演动作中的 disqus 代码:
# inside show.html.erb
<%= render raw 'comments' %>
# partial "comments"
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = '<%= Post::DISQUS_SHORTNAME %>';
var disqus_identifier = '<%= @post.id %>';
var disqus_url = '<%= url_for([:blog, @topic, @post])%>';
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>
In my model I define Post
, I define my short name like so:
在我定义的模型中Post
,我定义了我的简称:
DISQUS_SHORTNAME = if Rails.env.development?
"dev-shortname".freeze
else
"shortname".freeze
end
I can confirm the loading spinner is functioning but that is it. Am I missing something obvious? When I try to include only_path: false
as a second option in my url_for call, I get an exception stating I have supplied to many arguments to the method. Otherwise my disqus just hangs.
我可以确认加载微调器正在运行,但就是这样。我错过了一些明显的东西吗?当我尝试only_path: false
在我的 url_for 调用中包含第二个选项时,我收到一个异常,指出我已向该方法提供了许多参数。否则我的disqus就挂了。
采纳答案by You knows who
you should set this to make it work:
你应该设置它以使其工作:
var disqus_developer = 1; // this would set it to developer mode
Reference: http://ray247.wordpress.com/2009/09/02/how-to-develop-with-disqus-on-localhost/
参考:http: //ray247.wordpress.com/2009/09/02/how-to-develop-with-disqus-on-localhost/
回答by Rafael Lüder
None of the solutions above worked for me as of September 2013.
截至 2013 年 9 月,上述解决方案均不适用于我。
To get it to work I had to add localhostto the "Trusted Domains" list on this page:
为了让它工作,我必须将localhost添加到此页面上的“受信任的域”列表中:
http://[disqus_shortname].disqus.com/admin/settings/advanced/
http:// [disqus_shortname].disqus.com/admin/settings/advanced/
and also use the "Universal Code" found below to embed it into my blog posts:
并使用下面找到的“通用代码”将其嵌入到我的博客文章中:
http://[disqus_shortname].disqus.com/admin/settings/universalcode/
http:// [disqus_shortname].disqus.com/admin/settings/universalcode/
And it works! :)
它有效!:)
回答by Ken Hirakawa
Try setting disqus_url
to match your registered site URL.
尝试设置disqus_url
以匹配您注册的站点 URL。
回答by John Lehmann
The recommend solution seems to be to register multiple shortnames aka sites. This worked for me. E.g., balloons
and balloons-dev
.
推荐的解决方案似乎是注册多个短名称又名站点。这对我有用。例如,balloons
和balloons-dev
。
Make sure to modify the Javascript they give you to replace the shortname in the line which is below the comment about "do not modify", if want to dynamically set which site you're using based on your environment (e.g., "balloons" if not settings.DEBUG else "balloons-dev"
).
如果要根据您的环境(例如,"balloons" if not settings.DEBUG else "balloons-dev"
)动态设置您正在使用的站点,请确保修改他们提供给您的 Javascript,以替换“请勿修改”注释下方的行中的短名称。
回答by olayemii
This might be old now, but I fixed it by keeping the URL empty on both my script and my Disqus setting
这现在可能已经过时了,但我通过在脚本和 Disqus 设置中将 URL 保持为空来修复它
回答by Sergiy Kozachenko
For anyone in 2020 who faced this issue - I found that setting the shortname to my organization name in Disquss did the trick. And URL can be set to anything.
对于 2020 年遇到此问题的任何人 - 我发现在 Disquss 中将短名称设置为我的组织名称可以解决问题。并且 URL 可以设置为任何内容。
disqus_developer = 1
doesn't do anything.
disqus_developer = 1
什么都不做。
回答by airportyh
Disqus doesn't work on localhost as far as I know. It has always only worked on the production site for me. I believe it checks the hostname against the registered hostname.
据我所知,Disqus 在 localhost 上不起作用。它一直只适用于我的生产现场。我相信它会根据注册的主机名检查主机名。