小编Sha*_*nis的帖子

如何使用 Stack Exchange API 获取答案的正文?

我正在使用StackAPI来获取投票最多的问题以及这些问题的投票最多的答案:-

from stackapi import StackAPI
SITE = StackAPI('stackoverflow')
SITE.max_pages=1
SITE.page_size=10

questions = SITE.fetch('questions', min=20, tagged='python', sort='votes')
for quest in questions['items']:
    if 'title' not in quest or quest['is_answered'] == False:
        continue
    title = quest['title']
    print('Question :- {0}'.format(title))
    question_id = quest['question_id']
    print('Question ID :- {0}'.format(question_id))
    top_answer = SITE.fetch('questions/' + str(question_id) + '/answers', order = 'desc', sort='votes')
    print('Most Voted Answer ID :- {0}'.format(top_answer['items'][0]['answer_id']))
Run Code Online (Sandbox Code Playgroud)

现在使用这个answer_id我想得到答案的正文。我可以使用此 API 链接获取其余详细信息。

python python-3.x stackexchange-api

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

如何同时旋转和缩放图像?

我有一个图像元素

<img id="image">
Run Code Online (Sandbox Code Playgroud)

为了操纵图像,我有以下按钮: -

<div class="btn-group">
    <button type="button" class="js-zoom-in">
         Zoom In
    </button>
    <button type="button" class="js-zoom-out">
         Zoom Out
    </button>
    <button type="button" class="js-rotate-right">
         Rotate Right
    </button>
    <button type="button" class="js-rotate-left">
         Rotate Left
    </button>
</div>
Run Code Online (Sandbox Code Playgroud)

并处理相应的事件我使用下面的jquery: -

<script>
    var angle = 0;
    var scale = 1;
    $('.js-rotate-right').on('click', function() {
        angle += 15;
        $('#image').css('transform','rotate(' + angle + 'deg)');
    });
    $('.js-rotate-left').on('click', function() {
        angle -= 15;
        $('#image').css('transform','rotate(' + angle + 'deg)');
    });
    $('.js-zoom-in').on('click', function() {
        scale += 0.25;
        if(scale == 2.25){
          scale = 2;
        } …
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery

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

Django“on_delete=models.CASCADE”在 2.0 中不起作用?

我正在尝试使用 on_delete=models.CASCADE 创建一个简单的模型关系。
这是我的代码:-

class Answer_Options(models.Model):
    text = models.CharField(max_length=200)

class Quiz(models.Model):
    q_type = models.CharField(max_length=50)
    text = models.CharField(max_length=200)
    possible_answers = models.ManyToManyField(Answer_Options, on_delete=models.CASCADE)
Run Code Online (Sandbox Code Playgroud)

它在终端上给我以下错误:-
TypeError: _init__() got an意外关键字参数 'on_delete'
Location:- django\db\models\fields\lated.py", line 1129

python django

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

我怎么知道我的所有$ http GET请求都已完成?

使用AngularJs 1.6.5我使用for循环进行多个$ http GET调用.这是代码: -

for(var i=0; i < 11; i++){  
    var url = "/api/learner_qa/" + i;   
    $http.get(url).then(successCallback, errorCallback);    
    function successCallback(response){
        console.log(response);
    };
    function errorCallback(error){
        console.log(error);
    };
};
Run Code Online (Sandbox Code Playgroud)

我想要做的是在完成所有GET请求时触发一个函数.

我在这里提到了答案,并想知道如何在我的情况下在阵列上完成这个?

angularjs

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