小编Bea*_*own的帖子

Facebook登录错误"不允许用户查看该应用程序."

嗨:我已将我的应用程序提交到App Store.我的应用程序中有Facebook登录功能.当我尝试从设备登录Facebook时,我能够无缝地完成.然而,Apple拒绝了我的应用程序说"当我们点击Facebook图标进行注册时,我们将被带到移动Safari,我们会收到一条消息,指出:

不允许用户查看应用程序:不允许用户按开发人员集配置查看此应用程序.

不知道我怎么能重新创建这个问题.我在3个不同的设备上安装了我的应用程序,并且能够毫无错误地登录.我在Facebook的Facebook状态和评论部分检查了我的应用程序设置,我启用了我的普通公众.不确定我还缺少什么.我只是感到非常沮丧.有谁能帮我解决这个问题?我使用parse作为我的后端服务,并使用解析Facebook登录来记录用户.非常感谢你!

facebook login ios parse-platform

34
推荐指数
3
解决办法
2万
查看次数

防止自我转让的保护

我有这个测试文件:

"""module docstring"""


class Aclass:
    """class docstring"""

    def __init__(self, attr=None, attr2=None):
        self.attr = attr
        self.attr2 = attr2

    def __repr__(self):
        return 'instance_of the Aclass {self.attr}.'

    def __str__(self):
        return 'The A with: {self.attr}.'


def init_a():
    """function docstring"""
    a_inst = Aclass()
    attr = 1
    attr2 = 2
    a_inst.attr2 = attr2
    # should be: a_inst.attr = attr, but have a typo
    attr = attr
Run Code Online (Sandbox Code Playgroud)

我使用pylint对其进行了检查,输出显示一切正常。

$ pylint test.py 

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
Run Code Online (Sandbox Code Playgroud)

Based on the linting …

python pylint

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

Flask会话不会与并行请求一致更新

我注意到当并行运行的请求修改Flask时session,只记录了一些键.使用Flask的默认cookie会话和使用Redis后端的Flask-Session都会发生这种情况.该项目并不是新的,但只有在同一会议同时发生许多请求时,这才会变得明显.

import time
from flask import Flask, session
from flask_session import Session

app = Flask(__name__)
app.secret_key = "example"
app.config["SESSION_TYPE"] = "redis"
Session(app)

@app.route("/set/<value>")
def set_value(value):
    """Simulate long running task."""
    time.sleep(1)
    session[value] = "done"
    return "ok\n"

@app.route("/keys")
def keys():
    return str(session.keys()) + "\n"
Run Code Online (Sandbox Code Playgroud)

以下shell脚本演示了此问题.请注意,所有请求都已完成,但最终列表中只有一个键,并且测试运行之间不同.

#!/bin/bash
# set session
curl -c 'cookie' http://localhost:5007/keys
# run parallel
curl -b 'cookie' http://localhost:5007/set/key1 && echo "done1" &
curl -b 'cookie' http://localhost:5007/set/key2 && echo "done2" & 
curl -b 'cookie' http://localhost:5007/set/key3 && echo "done3" & …
Run Code Online (Sandbox Code Playgroud)

python curl flask flask-session

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

如何在flask-login中跟踪当前用户?

我试图在flask-login的视图中使用当前用户.所以我试着g object

我分配flask.ext.login.current_user给g对象

@pot.before_request
def load_users():
   g.user = current_user.username
Run Code Online (Sandbox Code Playgroud)

如果用户是正确的,它可以工作.但是当我使用错误的凭据进行注册或登录时,我收到此错误

AttributeError: 'AnonymousUserMixin' object has no attribute 'username'

请问我在哪里错了...

python flask python-2.7 flask-login flask-extensions

17
推荐指数
3
解决办法
5万
查看次数

Django自定义复杂的Func(sql函数)

在为精确找到Django ORM顺序的解决方案的过程中,我创建了一个自定义的django Func:

from django.db.models import Func

class Position(Func):
    function = 'POSITION'
    template = "%(function)s(LOWER('%(substring)s') in LOWER(%(expressions)s))"
    template_sqlite = "instr(lower(%(expressions)s), lower('%(substring)s'))"

    def __init__(self, expression, substring):
        super(Position, self).__init__(expression, substring=substring)

    def as_sqlite(self, compiler, connection):
        return self.as_sql(compiler, connection, template=self.template_sqlite)
Run Code Online (Sandbox Code Playgroud)

其工作原理如下:

class A(models.Model):
    title = models.CharField(max_length=30)

data = ['Port 2', 'port 1', 'A port', 'Bport', 'Endport']
for title in data:
    A.objects.create(title=title)

search = 'port'
qs = A.objects.filter(
        title__icontains=search
    ).annotate(
        pos=Position('title', search)
    ).order_by('pos').values_list('title', flat=True)
# result is
# ['Port 2', 'port …
Run Code Online (Sandbox Code Playgroud)

python django django-queryset django-annotate

13
推荐指数
3
解决办法
4944
查看次数

Pytest报告摘要以显示错误信息

我对pytest钩子和插件相对较新,我无法弄清楚如何让我的pytest代码给我测试执行摘要,但失败的原因.

考虑一下代码:

class Foo:
    def __init__(self, val):
        self.val = val

    def test_compare12():
        f1 = Foo(1)
        f2 = Foo(2)
        assert f1 == f2, "F2 does not match F1"

    def test_compare34():
        f3 = Foo(3)
        f4 = Foo(4)
        assert f3 == f4, "F4 does not match F3"
Run Code Online (Sandbox Code Playgroud)

当我使用-v选项运行pytest脚本时,它在控制台上给出了以下结果:

========================= test session starts=================================
platform darwin -- Python 2.7.5 -- py-1.4.26 -- pytest-2.7.0 --    /Users/nehau/src/QA/bin/python
rootdir: /Users/nehau/src/QA/test, inifile: 
plugins: capturelog
collected 2 items 

test_foocompare.py::test_compare12 FAILED
test_foocompare.py::test_compare34 FAILED

================================ FAILURES ===============================
_______________________________ test_compare12 _________________________

def test_compare12(): …
Run Code Online (Sandbox Code Playgroud)

python pytest

11
推荐指数
3
解决办法
4972
查看次数

我们可以在 Django ORM 中对 CharField 进行求和吗?

我在 Django ORM 中的模型是这样的

class Test(Modelbase):
    id = models.IntegerField(null=True, blank=True)
    amount = models.CharField(max_length=255)
Run Code Online (Sandbox Code Playgroud)

我想添加 id 列表的数量。唯一的问题是金额字段是CharField。如何为金额字段申请金额?

Test.objects.filter(id__in=[1,2,3]).aggregate(Sum('amount'))
Run Code Online (Sandbox Code Playgroud)

我正在Django=1.9.1为此使用。

django django-orm

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

Meta.fields包含一个未在此FilterSet上定义的字段:****

我正在使用Django Filters包.

我在视图中以下列方式定义了我的过滤器

class UnitFilter(django_filters.FilterSet):
    class Meta:
        model = Unit
        fields = [
            'floor', 'number', 'building','lease','leaseterm', 
            'lease__is_active','lease__is_terminated','lease__is_renewed',]
Run Code Online (Sandbox Code Playgroud)

我过滤的我的单位模型如下

class Unit(CommonInfo):
    version = IntegerVersionField( )
    number = models.CharField(max_length=30,null=True, blank=True)
    max_occupants = models.PositiveSmallIntegerField()
    floor = models.PositiveSmallIntegerField()
    rooms = models.PositiveSmallIntegerField()
    is_disabled_access = models.BooleanField(default=False)
    balcony_quantity = models.PositiveSmallIntegerField()
    building = models.ForeignKey(Building)
    recomended_price = models.DecimalField(max_digits=7, decimal_places=2)
    _lease = None
    _leaseterm = None
    #check = models.ManyToManyField(UnitCheck, through='UnitChecklist')

    def _get_total(self):

        from conditions.models import LeaseTerm
        from lease.models import Lease

        lease_dict = Lease.objects.filter(unit_id=self.id, is_active = True , is_terminated = False).aggregate(Max('id')) …
Run Code Online (Sandbox Code Playgroud)

django django-models django-filter

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

如何在不使代码看起来糟糕的情况下进行干净的日志记录?

我正在尝试编写干净的代码,所以我不希望我的代码被随机记录污染。这对我来说看起来很糟糕:

def generate_auth_token(self):
    logger.debug("Existing auth token: {}".format(self.auth_token))
    self.auth_token = uuid.uuid4()
    self.save()
    logger.debug("Updated auth token:  {}".format(self.auth_token))
    return str(self.auth_token)
Run Code Online (Sandbox Code Playgroud)

日志如下所示:

backend-api_1  | DEBUG: Device token: 66f4b515-c6f5-433c-885f-61c8a1f63ce5
backend-api_1  | Debug: Existing auth token: 66f4b515-c6f5-433c-885f-61c8a1f63ce5
backend-api_1  | Debug: Updated auth token: 66f4b515-c6f5-433c-885f-61c8a1f63ce5
Run Code Online (Sandbox Code Playgroud)

很难读取这样的代码。我想到了使用装饰器记录所有功能的想法。

backend-api_1  | DEBUG: Device token: 66f4b515-c6f5-433c-885f-61c8a1f63ce5
backend-api_1  | Debug: Existing auth token: 66f4b515-c6f5-433c-885f-61c8a1f63ce5
backend-api_1  | Debug: Updated auth token: 66f4b515-c6f5-433c-885f-61c8a1f63ce5
Run Code Online (Sandbox Code Playgroud)

上面的例子,现在看起来更干净了

def log_input_output(logger_name='', func_name=None, log_input_values=True):
  logger = logging.getLogger(logger_name)

  def _log_input_output_decorator(func):
    if not func_name:
      message_prefix = f'{func.__name__}'
    else:
      message_prefix = f'{func_name}'

    @wraps(func) …
Run Code Online (Sandbox Code Playgroud)

python django optimization logging

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

如何计算 Pandas 中多列的特定值

我有数据框

df = pd.DataFrame({
    'colA':['?',2,3,4,'?'],
    'colB':[1,2,'?',3,4],
    'colC':['?',2,3,4,5]
})
Run Code Online (Sandbox Code Playgroud)

我想计算'?'每列中的数量并返回以下输出 -

colA - 2
colB - 1
colC - 1
Run Code Online (Sandbox Code Playgroud)

有没有办法立即返回此输出。现在我知道怎么做的唯一方法是为每列编写一个 for 循环。

python pandas

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