path('endpoint/', views.Endpoint.as_view(), name='endpoint'),
On Thu, 30 Apr 2020 at 23:52, Milson Munakami<milsonmun@gmail.com> wrote:Hi Sahay,That is already--path('endpoint/', views.Endpoint.as_view(), name='get_endpoint'),
On Thu, Apr 30, 2020 at 1:15 PM 'Amitesh Sahay' via Django users <django-users@googlegroups.com> wrote:It should be Endpoint.as_view()
--On Thu, 30 Apr 2020 at 17:35, Milson Munakami<milsonmun@gmail.com> wrote:--Can anyone please help me to resolve this issue?
https://stackoverflow.com/q/61514512/1316060
My url path in project'surl.py
is defined as follows:path('endpoint/', views.Endpoint.as_view(), name='get_endpoint'),
The
views.py
include the following class to handle this routing:@method_decorator(csrf_exempt, name='dispatch') class Endpoint(View): def get(self, request, *args, **kwargs): ############ Here I can see the User Session ########## if not request.user.is_authenticated: return redirect('authentication_router') return redirect( 'https://app.globus.org/file-manager?method=POST&action=%s&cancelurl=%s&folderlimit=1&filelimit=0&label=%s' % ( request.build_absolute_uri(), "/", "To Transfer your Files Select the Folder first!") ) def post(self, request, *args, **kwargs): # On return from OAuth Page ############ Here, User Session return nothing so user is AnonymousUser ########## if request.POST.get('folder[0]'): # A Endpoint folder was selected endpoint_path = os.path.join(request.POST.get('path'), request.POST.get('folder[0]')) else: endpoint_path = request.POST.get('path') profile = request.user.userprofile # request.user does not has userprofile profile.endpoint_path = endpoint_path profile.save() return HttpResponseRedirect(reverse('authentication_router'))
The problem is when the get is called it finds the request.user value as authenticated user but once the redirect from OAUTH page with POST hits the class it loss all request user session and gives error at this line:
profile = request.user.userprofile
As,
request.user
seems loss its session and has value ofAnonymousUser
even though tillGET
method it is preserving the user's login session values.My
settings.py
file includes:INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', **'django.contrib.sessions',** 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', 'myapp', ] 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', ]
I am testing it in localhost:8000 .Please let me know what I am missing this code. Same code is perfectly working in Django 1.8 and Python 2.7. Recently, I am trying to upgrade it to work with Django 3 and Python 3. Only difference I can see is in
settings.py
in Django 1.8 version includes:'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
inMIDDLEWARE_CLASSES
which is removed in latest version of Django.--Thank you,
Milson
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAP1qhGui2o%3DDJD57Rq7GaiVO-s9wOgSdw1G-bNLPSYCL9Wkeuw%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1981496808.1824222.1588270514644%40mail.yahoo.com.
--Thank you,
Milson Munakami Mobile: 208.220.2943
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAP1qhGvo2X8%2BAPvqQGoOuVFOfhkmC%3DCkiByxfow6s4YVSzawnA%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1427974624.1821610.1588271666097%40mail.yahoo.com.
No comments:
Post a Comment