为了让用户在我们的django网站上可以使用google账号登录,这个功能可以通过django-allauth包来实现。如果没有安装,可以通过以下命令安装:pipinstalldjango-allauthConfiguration配置在django-allauth的官方文档中已经写的很详细,参考这里:https://django-allauth.readth。..CreateacertificateingoogleAPIs现在我们去googledeveloperconsole,在左边栏,找到APIs&Services:点击Credentials(证书)选项,然后我们来到证书页面:在页面顶部,点击CREATECREDENTIALS,选择OAuthclientID来创建证书:这里需要填写一个表格,三个选项名称:stdworkflow(这个名字在控制面板中用来标识证书,不会显示给终端用户)授权的JavaScript来源:https://stdworkflow.com(替换为您的域名)授权的重定向URI:https://stdworkflow.com/accounts/google/login/callback/(替换为您的域名,格式为相同)保存并完成。Atthistime,googlewillautomaticallygenerateaClientIDandClientsecretforyou.WritetheClientIDandClientsecrettothedatabaseMethod1:GUIManuallyaddittoourdatabase,anddjango-allauthwillcreateseveralprefixeswithsocialaccount_forus的表,我们需要修改其中的两个:socialaccount_socialappsocialaccount_socialapp_sitessocialaccount_socialappidprovidernameclient_idsecretkeyGoogleGoogleYOUR_CLIENT_IDYOUR_CLENT_SECRETid:不用填,由数据库自动生成(在后面socialaccount_socialapp_sites表中用得到)provider:Googlename:Googleclient_id:前面在APIs&Services中自动生成的client_idsecret:前面Client_secretkeyautomaticallygeneratedinAPIs&Services:leavesocialaccount_socialapp_sitesidsocialapp_idsite_id1(ifitisthefirstwebsite)1id:leaveitblank,orautomaticallygeneratedbythedatabasesocialapp_id:pk/idautomaticallygeneratedinthesocialaccount_socialapptableearlier(1inthisexample)site_id:1(Usually)Now,allconfigurationsarecompleted,visityourloginpage,youwillfindthatdjango-allauthautomaticallyaddsagoogleoption,clicktoregisterandloginthroughthegoogleaccount.方法二:命令行写入数据库下面是一个完整的例子,可以参考将以上数据写入socialaccount_socialapp和socialaccount_socialapp_sites表:[user@localhost]$mysql-uroot-pEnterpassword:mysql>useDATABASENAME;#用您的数据库名称替换“DATABASENAME”读取表信息以完成表和列名称您可以关闭此功能以更快地启动-ADatabasechangedmysql>insertintosocialaccount_socialappvalues(1,'Google','Google','YOUR_CLIENT_ID','YOUR_CLENT_SECRET','');QueryOK,1rowaffected(0.01sec)mysql>mysql>insertintosocialaccount_socialapp_sitesvalues(1,1,1);QueryOK,1rowaffected(0.01sec)mysql>退出再见