标签: django-rest-auth

找不到与“ account_email_verification_sent”相反的内容。'account_email_verification_sent'不是有效的视图函数或模式名称

我正在尝试在项目中使用allauth和rest-auth,并尝试在allauth中使用内置功能来进行电子邮件验证,但这是我得到的:

链接到我得到的屏幕截图

这是我的代码

settings.py

ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_EMAIL_REQUIRED = True
Run Code Online (Sandbox Code Playgroud)

urls.py

urlpatterns = [
re_path(r'^', include('rest_auth.urls')),
re_path(r'^registration/', include('rest_auth.registration.urls')),
]
Run Code Online (Sandbox Code Playgroud)

django django-rest-framework django-allauth django-rest-auth allauth

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

Django-rest-auth - Angular - 500 内部错误

或多或少,我正处于开发使用 Django Rest Framework 和 Angular 的应用程序的早期阶段。我决定使用django-rest-auth来管理所有用户与我的应用程序的集成。

由于我是 Angular 的新手,我不想使用 django-rest-auth Boilerplate Angular 应用程序来理解 Angular 的概念。我只想使用 django-rest-auth 端点。

问题是: 我的注册表单通过内部服务器 500,即使我的数据已传递并成功提交到 django.User 模型。

这是我的 Angular 应用程序:

// MODULE

var menuApp = angular.module('menuApp', ['ngRoute', 'ngCookies']);

//ROUTES
menuApp.config(function ($locationProvider, $routeProvider) {

$locationProvider.html5Mode({
enabled: true,
requireBase: false,
    hashPrefix:'!'
})

$routeProvider

.when('/', {
    templateUrl: '/static/app/pages/login.html',
    controller: 'homeCtrl'
})
.when('/register', {
    templateUrl: 'static/app/pages/register.html',
    controller: 'registerCtrl'
})

 menuApp.controller('homeCtrl', ['$log', '$scope', function($log,    $scope) {
        $log.info("homeCtrl is called ");
}]);

 menuApp.controller('registerCtrl', ['$scope', '$cookies', '$http','$location', …
Run Code Online (Sandbox Code Playgroud)

angularjs django-rest-auth

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

Django Rest Framework - 为什么尝试使用不正确的凭据登录用户时返回 200 状态代码?

这是我的 URLs.py:

url(r'^api-auth/', include('rest_framework.urls',
                               namespace='rest_framework')),
Run Code Online (Sandbox Code Playgroud)

我的主页上有一个表单,用户可以在其中键入用户名和密码。当提交按钮被点击时,AngularJS 使用用户对象(用户名和密码)向“api-auth/login/”发送一个 POST 请求:

$http.post("/api-auth/login/", self.loginuser)
    .error(function(data, status, headers, config) {
        console.log(data);
     });
Run Code Online (Sandbox Code Playgroud)

当用户提交不正确的用户名和密码(用户名和密码不存在或不匹配)时,Django Rest Framework 返回 200 OK 而不是 204 No Content、404 或 401 Unauthorized(在这篇文章中,它说 401是要返回的正确状态代码:如果用户尝试使用不正确的用户名/密码但格式正确登录,要返回的适当 HTTP 状态代码是什么?)。

根据这里:http : //www.w3.org/Protocols/rfc2616/rfc2616-sec9.html在第 9.5 节 POST 中,它说“在这种情况下,200(OK)或 204(无内容)是适当的响应状态,取决于响应是否包含描述结果的实体。”

如果数据存在,我会处理错误并记录数据(我在 JS 中做了 console.log(data)),但没有记录数据,这意味着(据我了解)没有数据发送/响应不包含描述的实体结果。

那么 DjangoRestFramework 为什么会返回 200 而不是 204 No Content(或者 404 或 401,根据我链接到的其他 SO 帖子应该返回什么)?

django angularjs django-rest-framework django-rest-auth

4
推荐指数
2
解决办法
2959
查看次数

如何在 Django Rest Framework Authtoken 中的令牌模型中添加字段

我正在使用rest_framework.authtoken.models令牌。我可以看到 3 个关键字段,created_at 和 user_id。

应用背景:

我使用 chrome 应用程序作为应用程序的客户端,我想使用令牌身份验证来连接 django Rest 框架中的 API。我想将 user_id 和 company_id 存储在authtoken_token表中。所以我可以只将令牌密钥存储在 chrome 应用程序本地存储中,

在此输入图像描述

  1. 我的问题是如何向该模型添加像 company_id 这样的额外字段?我找不到任何关于此的文档或文章。

  2. 我还在本文中给出了 Jamie 的答案,以对模型进行子类化,但我不知道如何进行。

谢谢!

django django-rest-framework django-rest-auth

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

在 django-rest-auth 中拥有“注销”端点有什么意义?

这篇文章中,我读到基于令牌的身份验证是无状态的,这意味着服务器不保留登录用户的记录。

另一方面,在django-rest-auth API 文档中提到了一个注销端点。它是做什么用的?

authentication django rest django-rest-auth

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

django-rest-auth facebook NoReverseMatch:未找到带有参数“()”和关键字参数“{}”的“socialaccount_signup”的反向。0 个图案

我正在使用django_rest_auth进行 Facebook 登录。

当我尝试通过 facebook api 登录时,我总是收到此错误

/rest_auth/facebook/

我尝试了这篇文章,没有帮助。

[04/Dec/2016 12:55:42] "POST /rest-auth/facebook/ HTTP/1.1" 500 126046
Internal Server Error: /rest-auth/facebook/
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Python27\lib\site-packages\django\views\decorators\csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "C:\Python27\lib\site-packages\django\views\generic\base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Python27\lib\site-packages\rest_framework\views.py", line 474, in dispatch
    response = self.handle_exception(exc)
  File "C:\Python27\lib\site-packages\rest_framework\views.py", …
Run Code Online (Sandbox Code Playgroud)

django-allauth django-rest-auth

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

Django 令牌授权 - 通过覆盖获取验证令牌类自定义获取_jwt_token

我的目标是覆盖obtain_jwt_token以更好地控制程序的返回值,在文档中我只发现了一个关于如何执行此操作的奇怪而粗略的信息:

请注意,默认的 acquire_auth_token 视图明确使用 JSON 请求和响应,而不是在您的设置中使用默认的渲染器和解析器类。如果您需要一个自定义版本的获取_auth_token 视图,您可以通过覆盖获取验证令牌视图类来实现,并在您的 url conf 中使用它

至于现在,我的尝试是这样的:

urlpatterns = [
   url(r'^api-token-auth/', my_customized_view),
]

class Foo(ObtainAuthToken):
    def post(self):
       # here goes my customized code

my_customized_view = Foo.as_view()
Run Code Online (Sandbox Code Playgroud)

赔率是我的代码看起来很愚蠢,而我只是失去了尝试谷歌它。我在 Djagno 方面的经验很少,所以请帮我解决这个问题!

django-rest-auth

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

Django-rest-auth:未找到“password_reset_confirm”的反转。“password_reset_confirm”不是有效的视图函数或模式名称

我正在尝试使用 django-rest-auth 密码重置功能,但在发布请求后,/rest-auth/password/reset/我收到标题中所述的错误(回溯),我不明白为什么。我遵循了文档页面中的安装过程。我的urls.py是:

from django.urls import include, path

urlpatterns = [
    path('users/', include('users.urls')),
    path('rest-auth/', include('rest_auth.urls')),
    path('rest-auth/registration/', include('rest_auth.registration.urls')),
Run Code Online (Sandbox Code Playgroud)

我还添加了所需的应用程序 settings.py

django django-rest-framework django-rest-auth

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

Django all auth:如何覆盖确认电子邮件 url

我想要做的是覆盖templates/account/email/email_confirmation_message.txt.

我想改变这部分

To confirm this is correct, go to {{ activate_url }}
Run Code Online (Sandbox Code Playgroud)

http://localhost:8080/confirm_email/{{ key }}
Run Code Online (Sandbox Code Playgroud)

然而,我无法弄清楚{{ activate_url }}从哪里来。我想将 发送key到由rest-auth.

如何重写电子邮件上的 url 链接?或者如果它太复杂了,在前端验证电子邮件的简单方法是什么?

django single-page-application django-rest-framework django-allauth django-rest-auth

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

Django Rest Framework 在登录或注册后返回用户配置文件和 api 令牌

我有以下序列化程序:

from rest_framework import serializers
from allauth.account import app_settings as allauth_settings
from allauth.utils import email_address_exists
from allauth.account.adapter import get_adapter
from allauth.account.utils import setup_user_email
from kofiapi.api.users.models import User, UserProfile

class UserProfileSerializer(serializers.ModelSerializer):

    class Meta:
        model = UserProfile
        fields = ('dob', 'phone', 'receive_newsletter')


class UserSerializer(serializers.HyperlinkedModelSerializer):

    profile = UserProfileSerializer(required=True)

    class Meta:
        model = User
        fields = ('url', 
                  'email', 
                  'first_name', 
                  'last_name',
                  'password',
                  'profile')
        extra_kwargs = {'password': {'write_only': True}}
        
    def create(self, validated_data):
        profile_data = validated_data.pop('profile')

        password = validated_data.pop('password')

        user = User(**validated_data)
        user.set_password(password)
        user.save()

        UserProfile.objects.create(user=user, **profile_data)

        return …
Run Code Online (Sandbox Code Playgroud)

django python-3.x django-rest-framework django-rest-auth

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