小编use*_*510的帖子

python-social-auth部分管道无法恢复

我正在尝试使用python-social-auth的部分管道为新用户收集密码.由于某些未知原因,我无法恢复管道,在提交表单后页面呈现回密码收集页面.

有线的是,即使我输入了http .../complete/backend-name,页面也会重定向回密码集合页面.看起来渲染进入无限循环,密码收集页面首先指向完整页面,完整页面直接返回密码收集页面.我检查了REDIRECT_FIELD_NAME的值,它是"下一步".

我不确定我的代码有什么问题,非常感谢任何提示/建议.

settings.py

SOCIAL_AUTH_PIPELINE = (
    ...
    'accounts.pipeline.get_password',
    ...
)
Run Code Online (Sandbox Code Playgroud)

pipeline.py

from django.shortcuts import redirect
from social.pipeline.partial import partial

@partial
def get_password(strategy, details, user=None, is_new=False, *args, **kwargs):
    if is_new:
        return redirect('accounts_signup_social')
    else:
        return
Run Code Online (Sandbox Code Playgroud)

views.py

def get_password(request):
    if request.method == 'POST':
        request.session['password'] = request.POST.get('password')
        backend = request.session['partial_pipeline']['backend']
        return redirect('social:complete', backend=backend)
    return render_to_response('accounts/social_signup.html',{"form":SocialSignUpForm}, RequestContext(request))
Run Code Online (Sandbox Code Playgroud)

django python-social-auth

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

如何在 Django 测试函数中添加/更改变量

这个问题可能很愚蠢,但我没有找到答案。

我想在 TestCase 的类中添加一个测试函数来检查测试的完成情况。例如,测试了 url,测试了表单等。因此,我想要一个变量来保存每个测试的记录。如果对 url 进行了测试,则 VARIABLE["urls"] = True。

不幸的是,看起来每个测试函数中的所有变量都被重置了。urls test VARIABLE["urls"] 中记录的消息不能进行其他测试。有没有办法在所有测试函数中使用全局变量?

这是修改后的工作代码

class Test(TestCase):
    test = {}
    to_be_test = ["urls","ajax","forms","templates"]

    def test_urls(self):
        ...
        self.test['urls'] = True

    def test_ajax(self):
        ...
        self.test['ajax'] = True

    def test_z_completion(self):
        for t in self.to_be_test:
            if not t in self.test:
                print "Warning: %s test is missing!" % t
Run Code Online (Sandbox Code Playgroud)

预期的结果应该是:

Warning: forms test is missing!
Warning: templates test is missing!
Run Code Online (Sandbox Code Playgroud)

python django django-testing

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