我正在按照本教程将 allauth 添加到我的项目中: http://django-allauth.readthedocs.org/en/latest/installation.html
尝试进行迁移时出现以下错误:“ImportError:没有名为 rest_authusers 的模块”
我的settings.py如下:
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'rest_auth'
'users',
# The Django sites framework is required
'django.contrib.sites',
'allauth.socialaccount.providers.facebook',
)
SITE_ID = 1
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(SETTINGS_PATH, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
# `allauth` needs this from django
'django.template.context_processors.request',
],
},
},
]
AUTHENTICATION_BACKENDS …Run Code Online (Sandbox Code Playgroud) 我正在尝试找出允许用户使用 django-allauth 删除或停用其帐户的最佳方法,并且我假设我需要将 is_active 字段设置为 False。
我的下面的解决方案有几个问题: 1) 呈现的复选框字段 is_active 显示文本“指定此用户是否应被视为活动用户。取消选择此选项而不是删除帐户。” 如何将此文本更改为“如果您确定要删除此帐户,请选中此框。”?
更新:刚刚意识到选中该框将 is_active 设置为 True,而取消选中该框将其设置为 False,所以也许我可能需要使用不同的字段来验证表单?
2) 如何在提交时注销用户?
形式.py:
class DeactivateUserForm(forms.ModelForm):
class Meta:
model = User
fields = ['is_active']
Run Code Online (Sandbox Code Playgroud)
视图.py:
login_required(login_url='/accounts/login/')
def deactivate_user_view(request):
pk = request.user.id
user = User.objects.get(pk=pk)
user_form = DeactivateUserForm(instance=user)
if request.user.is_authenticated() and request.user.id == user.id:
if request.method == "POST":
user_form = DeactivateUserForm(request.POST, instance=user)
if user_form.is_valid():
deactivate_user = user_form.save(commit=False)
user.is_active = False
deactivate_user.save()
return render(request, "account/userprofile_del.html", {
"user_form": user_form,
})
else:
raise PermissionDenied
Run Code Online (Sandbox Code Playgroud)
用户个人资料_del.html:
<h2>Delete your account</h2> …Run Code Online (Sandbox Code Playgroud) 我正在使用 Django allauth 和 django-rest-auth。我通过电子邮件确认实现了身份验证。但现在我意识到它不能完全正常工作,因为我没有在数据库中存储发送电子邮件确认(在管理中看不到它们)。电子邮件确认正在按应有的方式发送,并且工作完美,只是我在数据库中看不到它们。我缺少什么?
我使用 django-allauth 和 django-rest-auth 实现了注册和登录。我可以使用allauth 和rest-auth(网络和移动设备)成功使用Facebook 登录服务器。
当我尝试使用 FB 帐户登录时,其电子邮件已存在(有人已使用该电子邮件注册),它会显示注册表单。但是,当我尝试使用 Rest-auth 执行相同操作时,出现错误:
Internal Server Error: /rest-auth/facebook/
IntegrityError at /rest-auth/facebook/
duplicate key value violates unique constraint "auth_user_username_key"
DETAIL: Key (username)=() already exists.
Run Code Online (Sandbox Code Playgroud)
我的配置:
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'optional'
SOCIALACCOUNT_AUTO_SIGNUP = True
SOCIALACCOUNT_EMAIL_VERIFICATION = False
SOCIALACCOUNT_EMAIL_REQUIRED = True
SOCIALACCOUNT_QUERY_EMAIL = True
Run Code Online (Sandbox Code Playgroud) django facebook-login django-rest-framework django-allauth django-rest-auth
使用 django-allauth,成功登录后,用户被重定向到http://<myproject>/accounts/profile/...但是此 URL 不存在,但它仍然成功显示来自http://<myproject>/profile/
设置.py
urlpatterns = [
path('', include('pages.urls')),
path('admin/', admin.site.urls),
url(r'^accounts/', include('allauth.urls')),
url('album/', include('albums.urls')),
url('profile/', include('user_profile.urls')),
]
Run Code Online (Sandbox Code Playgroud)
用户个人资料\urls.py
urlpatterns = [
path('', views.profile, name='profile'),
]
Run Code Online (Sandbox Code Playgroud)
使用show_urls我没有看到任何/accounts/*可以调用view.profile视图的内容
/accounts/confirm-email/ allauth.account.views.EmailVerificationSentView account_email_verification_sent
/accounts/confirm-email/<key>/ allauth.account.views.ConfirmEmailView account_confirm_email
/accounts/email/ allauth.account.views.EmailView account_email
/accounts/inactive/ allauth.account.views.AccountInactiveView account_inactive
/accounts/login/ allauth.account.views.LoginView account_login
/accounts/logout/ allauth.account.views.LogoutView account_logout
/accounts/password/change/ allauth.account.views.PasswordChangeView account_change_password
/accounts/password/reset/ allauth.account.views.PasswordResetView account_reset_password
/accounts/password/reset/done/ allauth.account.views.PasswordResetDoneView account_reset_password_done
/accounts/password/reset/key/<uidb36>-<key>/ allauth.account.views.PasswordResetFromKeyView account_reset_password_from_key
/accounts/password/reset/key/done/ allauth.account.views.PasswordResetFromKeyDoneView account_reset_password_from_key_done
/accounts/password/set/ allauth.account.views.PasswordSetView account_set_password
/accounts/signup/ allauth.account.views.SignupView account_signup
/accounts/social/connections/ allauth.socialaccount.views.ConnectionsView socialaccount_connections
/accounts/social/login/cancelled/ …Run Code Online (Sandbox Code Playgroud) 我对 Django 相当陌生,所以我一直在遵循教程和指南来学习。我目前正在尝试按照 freeCodeCamp 的 youtube 教程来做一个电子商务 Django 项目。
一开始你需要安装我已经完成的 Django-AllAuth。
我当前遇到的问题是,当您需要迁移已安装的应用程序时,它会在设置中的 Authentication_Backends 部分的“django.contrib.auth.backends.ModelBackend”上向我抛出“无效语法错误”。
我的设置.py
import os
ENVIRONMENT = os.getenv('ENVIRONMENT', 'development')
DEBUG = True
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = '-05sgp9!deq=q1nltm@^^2cc+v29i(tyybv3v2t77qi66czazj'
ALLOWED_HOSTS = []
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'core'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware'
]
ROOT_URLCONF = 'ecommerce.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth', …Run Code Online (Sandbox Code Playgroud) 我正在使用带有 allauth 的自定义用户模型,并且需要省略用户名字段。我已经看过文档和一大堆关于使用的 stackoverflow 答案ACCOUNT_USER_MODEL_USERNAME_FIELD = None,但所有这些仍然导致我的数据库有一个用户名字段。
现在,由于数据库仍然有一个username设置了唯一约束的字段,并且allauth 不会在上述设置设置为 的字段中放置用户名,这导致我在第一个用户创建后None面临。IntegrityError我知道我可以通过设置上述设置来解决这个问题,'username'但我很好奇,我如何不创建用户名,因为我从不使用它。
我的型号:
class CustomUser(AbstractUser):
# Custom user model for django-allauth
first_name = None
last_name = None
def delete(self):
# Custom delete - make sure user storage is also purged
# Purge the user storage
purge_userstore(self.email)
# Call the original delete method to take care of everything else
super(CustomUser, self).delete()
Run Code Online (Sandbox Code Playgroud)
除了覆盖该函数之外,它实际上并没有做太多事情delete。此覆盖与本主题无关,但我将其包含在内只是为了完整性。它还设置first_name和last_nameto None,它可以完美地工作并按预期从数据库中删除这些字段。我尝试过设置user …
我一直在关注 William Vincent 撰写的关于 django for apis 的教程。我需要使用 django-allauth。我已将其安装在我的 venv 中,将其添加到已安装的应用程序中,并根据 Documentation 上的安装说明完成了所有必要的操作。运行时python manage.py migrate,错误返回为ImportError: allauth needs to be added to INSTALLED_APPS.
这是我的settings.py中的相关区域
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.sites",
# 3rd party libraries
"rest_framework",
"corsheaders",
"rest_framework.authtoken",
"allauth",
"allauth.account",
"allauth.socialaccount",
"dj_rest_auth",
"dj_rest_auth.registration",
# Local
"accounts",
"posts",
]
......
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"django.template.context_processors.request",
],
},
},
]
.... …Run Code Online (Sandbox Code Playgroud) 我正在使用Django 1.7和python 3.4.我正在尝试使用django-allauth进行用户身份验证,我正在关注此链接http://www.sarahhagstrom.com/2013/09/the-missing-django-allauth-tutorial/ 但是我在尝试时遇到此问题迁移应用程序.
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\django\apps\config.py", line 118, in creat
e
cls = getattr(mod, cls_name)
AttributeError: 'module' object has no attribute 'sitesallauth'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line
385, in execute_from_command_line
utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line
354, in execute
django.setup()
File "C:\Python34\lib\site-packages\django\__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python34\lib\site-packages\django\apps\registry.py", line 85, in popu
late
app_config = AppConfig.create(entry) …Run Code Online (Sandbox Code Playgroud) 我一直在按照说明为我的网站设置django-allauth程序包,并且一切正常,直到注册后发送确认电子邮件。一切似乎都正常,因为我注册了并且有关新帐户的信息在数据库(user表和account_emailaddress表)中,但未发送电子邮件(表中没有内容account_emailconfirmation)。EMAIL_BACKEND设置为,django.core.mail.backends.console.EmailBackend并且没有任何日志错误。
我一直在调试,并且注意到工作流程如下:
form_valid内部SignupView方法调用的complete_signup方法complete_signup 呼吁 perform_login然后,perform_login检查的第一个条件是if not user.is_active我认为在注册时始终会满足该条件,因为默认情况下新用户不处于活动状态。因此,每个注册用户都被重定向到帐户非活动页面(return HttpResponseRedirect(reverse('account_inactive')))。
我看过评论:
# Local users are stopped due to form validation checking
# is_active, yet, adapter methods could toy with is_active in a
# user_signed_up signal. Furthermore, social users should be
# stopped anyway.
Run Code Online (Sandbox Code Playgroud)
这是否意味着我应该采取一些措施使我的确认电子邮件像下一封一样发送?
@receiver(user_signed_up)
def after_user_signed_up(sender, request, user):
send_email_confirmation(request, user, signup=signup)
Run Code Online (Sandbox Code Playgroud)
我认为该程序包可以正常工作,但我不明白为什么这样做会如此,感谢您的帮助。
提前致谢。