ImproperlyConfigured at /api/v1/auth/registration/account-email-verification-sent/ - django

I'm getting this error when trying to signup after updating dj-rest-auth package to 3.0.0 from 1.1.0.
main urls.py
from allauth.account.views import confirm_email
from dj_rest_auth.registration.views import VerifyEmailView
from dj_rest_auth.views import PasswordResetConfirmView
from django.urls import include, path, re_path][1]][1]
path("api/v1/auth/", include("dj_rest_auth.urls")),
path(
"api/v1/auth/registration/", include("dj_rest_auth.registration.urls")
),
path("api/v1/auth/registration/verify-email/", VerifyEmailView.as_view()),
path(
"api/v1/auth/password/reset/confirm/<slug:uidb64>/<slug:token>/",
PasswordResetConfirmView.as_view(),
name="password_reset_confirm",
),
re_path(
r"^api/v1/auth/accounts-rest/registration/account-confirm-email/(?P<key>.+)/$",
confirm_email,
name="account_confirm_email",
),

Related

Could not import 'rest_framework_jwt.authentication.JSONWebTokenAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'

Full Error:
Could not import 'rest_framework_jwt.authentication.JSONWebTokenAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: cannot import name 'smart_text' from 'django.utils.encoding'
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
),
}
And this is the pip freeze in the virtual env:
(backend) PS D:\js\backend> pip freeze
asgiref==3.5.1
Django==4.0.4
django-cors-headers==3.11.0
djangorestframework==3.13.1
djangorestframework-jwt==1.11.0
djangorestframework-simplejwt==5.1.0
mysqlclient==2.1.0
PyJWT==1.7.1
pytz==2022.1
sqlparse==0.4.2
tzdata==2022.1
in the middle of the error, it addresses some lines across views.py for decorators:
from http.client import HTTPResponse
from multiprocessing import context
from django.shortcuts import render
from django.http import HttpResponse, Http404, JsonResponse
from .models import Tweet
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
from rest_framework.decorators import api_view, permission_classes
from rest_framework import status
I'm not sure if they're even related
'rest_framework_jwt.authentication.JSONWebTokenAuthentication' this is provided by djangorestframework-jwt wich is not not being maintained anymore . Just uninstall it
instead use 'rest_framework_simplejwt.authentication.JWTAuthentication'
that comes from djangorestframework-simplejwt
1 - install djangorestframework-simplejwt : pip install djangorestframework-simplejwt
2- Your 'DEFAULT_AUTHENTICATION_CLASSES' should be like this :
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
'rest_framework_simplejwt.authentication.JWTAuthentication',
),
3 - in your root urls.py file (or any other url config), include routes for Simple JWT’s TokenObtainPairView and TokenRefreshView views:
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
)
urlpatterns = [
...
path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
...
]
for more information check the official documentation

Django Rest Swagger Not showing up all the APIs

I am working with Django Rest swagger. But it's not showing up all the APIs.
The url paths for /tickets are missing:
Even path to /dj-rest-auth/user/ is missing as well:
Backend/urls.py
from django.contrib import admin
from django.urls import path, include
from rest_framework_swagger.views import get_swagger_view
schema_view = get_swagger_view(title='API')
urlpatterns = [
path('admin/', admin.site.urls),
#path('api/v1/', include(api_urlpatterns)),
#path('dj-rest-auth/', include('dj_rest_auth.urls')),
path('dj-rest-auth/', include('dj_rest_auth.urls')),
path('dj-rest-auth/registration/', include('dj_rest_auth.registration.urls')),
path('api/', include('ticket.urls')),
path('swagger/', schema_view)
]
Tickets/urls.py
from django.urls import path
from ticket import views
urlpatterns = [
path('tickets/', views.ticket_list),
path('tickets/<int:pk>/', views.ticket_detail),
]
My directory structure:
Try with below code:
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.AllowAny',
),
.......
.......
}
I solved this by going in settings.py file and set DEBUG=True.

How can show django auth-views URLs on swagger?

I set the Urls like belows.
users>urls.py
from django.urls import path
from django.contrib.auth import views as auth_views
from users import views
....
path(
"changePassword/", auth_views.PasswordResetView.as_view(), name="password_reset"
), # 비밀번호 변경 (링크 발송)
path(
"changePasswordDone/",
auth_views.PasswordResetDoneView.as_view(),
name="password_reset_done",
), # 비밀번호 변경(링크 선택 후 화면)
path(
"changePasswordConfirm/<uidb64>/<token>/",
auth_views.PasswordResetConfirmView.as_view(),
name="password_reset_confirm",
), # 비밀번호 변경(사용자 전송 링크)
path(
"changePasswordComplete/",
auth_views.PasswordResetCompleteView.as_view(),
name="password_reset_complete",
), # 비밀번호 변경(사용자 새 비밀번호 입력 후)
]
but the auth_views doesn't appear in the swagger like below images.
I guess there is some problem in the settings.py.... but don't know the detail.
config>settings.py
# Rest_Framework JWT
REST_FRAMEWORK = {
"DEFAULT_PERMISSION_CLASSES": (
# 'rest_framework.permissions.IsAuthenticated', #401 에러 회피
"rest_framework.permissions.AllowAny", # 401 에러 회피
),
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework_simplejwt.authentication.JWTAuthentication",
# 'rest_framework.authentication.SessionAuthentication',
# 'rest_framework.authentication.BasicAuthentication',
),
}
could you help kindly please?

Getting error : 'admin' is not a registered namespace, on trying to access the password reset view

I created a password reset view following this tutorial.
I used the urls for class based views since django uses CBVs in the version 2.1 and above. It seemed to work fine, but today I am getting the above stated error. I have commented the admin url, on uncommenting it the password_reset view works, but through the django registration and uses it's own template regardless of the templates I have created. Why am I getting this problem suddenly when it worked fine earlier?
urls.py
from django.conf.urls import url,include
from django.contrib import admin
from NewApp import views
from django.conf import settings
from django.conf.urls.static import serve
from django.urls import path
urlpatterns = [
url(r'^$', views.user_login , name='user_login'),
url(r'^NewApp/', include('NewApp.urls', namespace="NewApp")),
path('', include('django.contrib.auth.urls')),
]
NewApp/urls.py
from django.conf.urls import url,include
from django.urls import path
from . import views
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.auth import views as auth_views
app_name = 'NewApp'
urlpatterns = [
path('password_reset/', auth_views.PasswordResetView.as_view(), name='password_reset'),
path('password_reset/done/', auth_views.PasswordResetDoneView.as_view(), name='password_reset_done'),
path('reset/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
path('reset/done/', auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),
]
Apart from these, I have only used templates which are just copied from the link I have mentioned.
views for password reset need to access the admin by default. So you have to include the admin site to urls.py:
from django.urls import path
from django.contrib import admin
urlpatterns = [
...
path('admin/', admin.site.urls),
...
]

Best way to translate Django generic view

I am upgrading to Django 1.5 which has since deprecated generic views. I am using django-voting which used generic views. I am not sure how to translate this into a class based view:
from django.conf.urls.defaults import *
from django.views.generic.list_detail import object_list
from django.core.context_processors import request
from django.shortcuts import get_object_or_404, render_to_response
from blog.models import Blog
from voting.views import vote_on_object
from voting.models import Vote
import operator
urlpatterns = patterns('',
url(r'^links/(?P<object_id>\d+)/(?P<direction>up|down|clear)vote/?$',
vote_on_object,
dict(
model=Blog,
template_object_name='link',
template_name='blog/link_confirm_vote.html',
allow_xmlhttprequest=True,
),
name="link_vote",)
)
views.py
class BlogDetailView(DetailView):
model = Blog
template_name = 'idea/link_confirm_vote.html'
urls.py
from .views import BlogDetailView
urlpatterns = patterns('',
url(
regex=r'^links/(?P<object_id>\d+)/(?P<direction>up|down|clear)vote/?$',
view=BlogDetailView.as_view(),
name='link_vote'
),
)