小编Yog*_*ogi的帖子

警报("嗨!")和功能()之间的区别{alert("嗨!")}

当我们在按钮中执行内联命令时:

<button id="myButton" onclick="alert('Hi!')"> 
Run Code Online (Sandbox Code Playgroud)

为什么

document.getElementById("myButton").onclick = alert('Hi!') 
Run Code Online (Sandbox Code Playgroud)

不起作用,但在页面加载时发出警报?我无法理解function()添加到它和没有它是如何工作的function().我希望你们理解我的问题.我在这里遗漏了一些东西.

javascript dom

24
推荐指数
5
解决办法
3972
查看次数

如何根据url请求更改django listview中的模板名称?

我有 2 个模板来渲染一个列表视图,我根据用户给出的请求 url 选择模板。我知道,我可以分别在 2 个单独的 url 上为 2 个模板添加 2 个类。例如

class MyListView1(generic.ListView):
     template_name = 'myapp/list_one.html'
     .....
     .....

class MyListView2(generic.ListView):
     template_name = 'myapp/list_two.html'
     .....
     .....
Run Code Online (Sandbox Code Playgroud)

但是有没有一种方法可以检查一个类中的 url 请求并根据它在一个 listview 类中渲染模板?就像是

class MyListView(generic.ListView):

   if request.path == '/list1'
         template_name = 'myapp/list_one.html'
   if request.path == '/list2'
         template_name = 'myapp/list_two.html'
Run Code Online (Sandbox Code Playgroud)

我知道这不是有效的代码,但只是为了可视化

python django

7
推荐指数
1
解决办法
7141
查看次数

每当我的json数据文件发生更改时如何刷新页面

所以我有一个名为'data.json'的本地文件包含各种数据.我只想在json文件中的某些数据发生变化时刷新页面.如果您能用一些代码解释我,请感谢您的帮助.我在互联网上搜索,我找不到合适的答案.

javascript jquery json

6
推荐指数
1
解决办法
3万
查看次数

如何在 d3.js 中填充我的 svg 圆圈内的图像

这是我在 svg 中填充圆圈的一段代码。

   var svgContainer = d3.select("body").append("svg")
                                 .attr("width", 1000)
                             .attr("height", 1000);
    var circles = svgContainer.selectAll("circle")
                      .data(nodes)
                      .enter()
                      .append("circle");

     var circleAttributes = circles
                   .attr("cx", function (d) { return d.x_axis; })
                   .attr("cy", function (d) { return d.y_axis; })
                   .attr("r", function (d) { return d.radius; })
                   .attr('fill', 'green')
Run Code Online (Sandbox Code Playgroud)

但不是在我的圆圈内填充绿色,我想在每个圆圈内填充不同的图像,其中 url 在我的 json 数据中。我一直在尝试使用 .attr('fill', url(function(d) {return d.url})) 但它不起作用。我是 d3 的新手,谁能帮我解决这个任务?

javascript svg d3.js

5
推荐指数
2
解决办法
8967
查看次数

从元组中过滤pandas数据帧

AB_col = [(0,230), (10,215), (15, 200), (20, 185), (40, 177), 
                (0,237), (10,222), (15, 207), (20, 192), (40, 184)]

sales = [{'account': 'Jones LLC', 'A': 0, 'B': 230, 'C': 140},
         {'account': 'Alpha Co',  'A': 20, 'B': 192, 'C': 215},
         {'account': 'Blue Inc',  'A': 50,  'B': 90,  'C': 95 }]
df = pd.DataFrame(sales)
print df
Run Code Online (Sandbox Code Playgroud)

结果
DF

现在,上面的数据帧必须由AB_col元组列表进行过滤.我试过类似的东西

df[df["A","B"].zip.isin(AB_col)]
Run Code Online (Sandbox Code Playgroud)

但它不起作用,如何将上述数据帧过滤到如下所示的数据帧

dfexpected

python pandas

4
推荐指数
1
解决办法
1873
查看次数

如何修复 Django Translation ASCII 解码错误?

我有这个 django 网站从 locale/lc_messages/django.po 和 django.mo 文件从英语翻译成德语。但是,当我尝试翻译像 ü 和 ä 这样的德语字母时,它给了我错误

'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)

据我所知,django 正在尝试通过 ASCII 解码 unicode 字符,这是不可能的。但是我该如何解决这个问题?我应该在哪里设置 django 以通过 utf-8 而不是通过 ASCII 解码。或者让我知道我是否错了。

追溯:

DjangoUnicodeDecodeError at /de/
'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128). You passed in <django.utils.functional.__proxy__ object at 0x0000000005EB40B8> (<class 'django.utils.functional.__proxy__'>)
Request Method: GET
Request URL:    http://127.0.0.1:8000/de/
Django Version: 1.10.1
Exception Type: DjangoUnicodeDecodeError
Exception Value:    
'ascii' codec can't decode …
Run Code Online (Sandbox Code Playgroud)

python django unicode ascii utf-8

3
推荐指数
1
解决办法
1321
查看次数

如何在 Django 中连接到 redis?

CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379/1",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试连接到 redis 以将我的对象保存在其中,但是当我尝试连接时它给了我这个错误

连接到 127.0.0.1:6379 时出现错误 10061。无法建立连接,因为目标机器主动拒绝它

它是如何工作的,我应该在位置上提供什么,而且我是我公司的代理人。需要一些关于位置的详细解释。

python django redis

2
推荐指数
1
解决办法
6048
查看次数

如何在表格行上启用锚标记?

<div class="table-responsive">
    <table class="table table-bordered">
       <tbody> 
            <tr>
                <th>head1</th>
                <th>head2</th>
                <th>head3</th>
                <th>head4</th>
                <th>head5</th>
                <th>head6</th>
                <th>head7</th>
            </tr>

            <a href="#">
                <tr>
                    <td>col1</td>
                    <td>col2</td>
                    <td>col3</td>
                    <td>col4</td>
                    <td>col5</td>
                    <td>col6</td>
                    <td>col7</td>
                </tr> 
             </a>

        </tbody>

    </table>
</div>
Run Code Online (Sandbox Code Playgroud)

我有这个 html 页面,我需要将整行作为锚标记,这样当我将鼠标悬停在该行上并单击它时,我可以转到另一个页面。但是当我尝试执行它时,DOM 将锚标记抛出到表标记之外,并且它不起作用。我怎样才能实现这个?

html javascript twitter-bootstrap

1
推荐指数
1
解决办法
5208
查看次数

如何在ubuntu中为终端设置代理?

我的场景:

我正在尝试在我新安装的ubuntu中安装python和postgresql,它通过windows 7上的virtualbox运行。它使用我公司的网络,并且我已经在ubuntu的网络设置中设置了代理。

我可以使用 mozilla(ubuntu) 浏览和下载,没有任何问题。

问题:

但是当我尝试使用终端安装软件包时,它只是停在 0% 处。它尝试了各种 IP,但 我的终端截图仍然为 0%

[更新] - 最终无法连接到IP

尝试过:

我已经尝试过通过导出代理设置

sudo -H gedit /etc/profile.d/proxy.sh

并更新了文件

导出http_proxy= http://用户名:密码@proxyhost:端口/

(我也设置为https)

请让我知道出了什么问题?

python linux ubuntu proxy virtualbox

0
推荐指数
2
解决办法
4万
查看次数