python-social-auth生成'connect with'链接作为字符串

时间:2017-08-29 08:42:49

标签: python django

我正在使用social-auth-app-django来支持使用社交应用进行登录。 此代码位于angular-djangorest应用程序上,因此django基本上不提供html页面。

现在从文档中我可以看到,如果我确实提供了html页面,我只需添加以下行来生成'connect with'链接:

 <a href="{% url 'social:begin' 'instagram' %}">Login with Instagram</a>

但由于我自己不提供html,我需要提供{% %}自己在def connect_with_instagram(request): . . return HttpResponseRedirect(<the 'connect with' string>) 之间生成的字符串的角度应用。

例如

require_once APPPATH . '/third_party/Phpexcel/Bootstrap.php';



    // Create new Spreadsheet object
        $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

//Change to excel2007 excel5

$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, '**Excel5**');

$writer->save('php://output');

那么如何生成这个字符串?

1 个答案:

答案 0 :(得分:1)

{% url 'social:begin' 'instagram' %}

正常的django python代码中的

将是:

from django.urls import reverse
reverse('social:begin', args=['instagram'])

这样结束:

from django.urls import reverse

def connect_with_instagram(request):
    .
    .
    return HttpResponseRedirect(reverse('social:begin', args=['instagram']))