小编Bip*_*ain的帖子

按字典顺序python排序字​​符串

我想按字典顺序将字符串排序到列表中

str='aAaBbcCdE'
Run Code Online (Sandbox Code Playgroud)

['A','a','a','B','b','C','c','d','E']
Run Code Online (Sandbox Code Playgroud)

sorted()给我这个输出:

['A','B','C','E','a','a','b','c','d']
Run Code Online (Sandbox Code Playgroud)

如何按字典顺序排序?

python sorting lambda

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

在同一个域中发送没有cookie的ajax请求?

我看到google或twitter autosuggest发送的ajax请求非常轻量级,因为它们不会发送任何带有请求的cookie.我想知道他们是怎么做到的?我搜索了一些方法,但我找到了通过CORS发送的方式,但他们将请求发送到同一个域.

关于如何做到这一点的任何想法或方法.我正在使用铬.

提前致谢

cookies ajax jquery http xmlhttprequest

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

NotAllowedError:必须处理用户手势才能执行共享请求。navigator.share

我有一个简单的页面,其中包含我通过 AJAX 请求处理的一些详细信息。在 AJAX 调用成功回调时,我试图触发navigator.share它给我一个错误:

NotAllowedError:必须处理用户手势才能执行共享请求。

一些示例代码如下所示:

$("#form-button").on('click', function (event) {
  var ele = $(this);
  event.preventDefault();
  $.ajax({
    // ...
    dataType: "json",
    data: { "foo": "bar" },
    success: function (response) {
      if (navigator.share) {
        navigator.share({
          title: response.text,
          text: response.text,
          url: response.href
        }).then(function () {
          alert('Successful share')
        }).catch(function (error) {
          alert('Error sharing: ' + error);
        });
      }
    },
  });
});
Run Code Online (Sandbox Code Playgroud)

来自Google 开发者网站的Wuoting指出:

...您只能调用 API 来响应用户操作,例如单击(例如,您不能在页面加载过程中调用 navigator.share)

如果我没有 AJAX 调用并直接navigator.share在 click 事件下触发,但当我将其放入 AJAX 回调时则无效。我希望 API 会检查事件链。

我必须有哪些替代方法才能使其发挥作用?我试过保留一个虚拟按钮并触发点击。

jquery share google-chrome mobile-chrome

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

使 django modelchoicefield readonly true

在我的编辑页面上,我试图允许用户编辑/更改他们输入的内容,但条件之一是他们无法编辑模型选择字段。

所以,我尝试了这个命令,但它不起作用。使用“readonly = True”用户仍然可以更改模型选择字段“下拉文件”,而使用“disabled = True”用户无法更改模型选择字段,但当他们尝试提交时会收到此错误:“此字段是必需的。”

myform.py

class NameForm(forms.ModelForm):
    class Meta:
         model=Name
         fields = '__all__'

    def __init__(self, *args, **kwargs):
         super(NameForm, self).__init__(*args, **kwargs)
         self.fields['names'].widget.attrs['disabled'] = 'True'
         #self.fields['names'].widget.attrs['readonly'] = True
Run Code Online (Sandbox Code Playgroud)

有人有解决方案吗..?

提前致谢

django jquery

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

如何为动态 url 构建 nock 正则表达式

我如何为以下类型的 url 构建 nock 配置

http://example.com/harry/potter?param1=value1
Run Code Online (Sandbox Code Playgroud)

http://example.com/harry/<value1>
Run Code Online (Sandbox Code Playgroud)

我有两种类型的 url,首先是我可以在其中查询参数,尽管基本 url 是固定的。

第二个是基本 url 具有动态值的地方。

目前我有

before(function(){
   nock('http://example.com')
       .get('/terminal/chrome_log')
       .reply(200, "OK");

  nock('http://example.com')
       .get(function(uri) {
           return uri.indexOf('harry') >= 0;
       })
        .reply(200, "OK");
    });
Run Code Online (Sandbox Code Playgroud)

了解与 node nock 一起使用的东西会很有帮助。

api node.js nock

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

如何在背景中绘制文字和图像?

我想做一个像蟒蛇这样的东西。 示例图片

我将图像放在背景中并用透明填充写入文本,以便显示图像。

python alpha python-imaging-library

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