ઉકેલાયેલ: Django rest_framework-social-oauth2

મુખ્ય સમસ્યા એ છે કે Django rest_framework-social-oauth2 OAuth 2.0 નો ઉપયોગ કરીને પ્રમાણીકરણને સપોર્ટ કરતું નથી. આનો અર્થ એ છે કે તમે તેનો ઉપયોગ એવા વપરાશકર્તાઓને અધિકૃત કરવા માટે કરી શકતા નથી કે જેઓ તમારી વેબસાઇટ પર પહેલેથી લૉગ ઇન નથી.

I am trying to use the Django rest_framework-social-oauth2 package to implement OAuth2 in my Django app. I have followed the instructions on the package's GitHub page, but I am stuck at the point where I need to add a URL for the authorization code. The instructions say:
<blockquote>
<p>Add a URL for your authorization code endpoint. For example:</p>
</blockquote>
<code>url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
</code>
However, when I add this line of code to my urls.py file, it does not work and gives me a 404 error when I try to access any of my URLs (including /admin). If I remove this line of code, everything works fine again. 


A:

You need to add <code>rest_framework_social_oauth2</code> urls in your project urls file like below : 
<code>(r'^o/', include('rest_framework_social_oauth2.urls')), # Add this line in your project urls file 

    urlpatterns = [

        url(r'^admin/', admin.site.urls),

        (r'^o/', include('rest_framework_social_oauth2.urls')), # Add this line in your project urls file 

    ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + static(settings.STATICFILES) # This is for media files and static files path setting   . You can skip this if you don't want media and static files path setting .   `static` is used for adding media and static files path setting . `staticfiles` is used for adding only static files path setting .   If you want both then use both like above or if you want only one then use that one alone like below : 

    urlpatterns = [

        url(r'^admin/', admin.site.urls),

        (r'^o/', include('rest_framework_social_oauth2')), # Add this line in your project urls file 

    ] + staticfiles() # This is only used for adding only static files path setting . If you want both then use both like above or if you want only one then use that one alone like below : 

    urlpatterns = [

        url(r'^admin/', admin.site.urls),

        (r'^o/', include('rest framework social oauth 2')), # Add this line in your project urls file 

    ] + static() # This is only used for adding media and static files path setting . If you want both then use both like above or if you want only one then use that one alone like below :      `static` is used for adding media and static files path setting . `staticfiles` is used for adding only static files path setting .   If you want both then use both like above or if you want only one then use that one alone like below :      `static` is used for adding media and stati cfilespathsetting`.`staticfilesisusedforaddingonlystati cfilespathsetting`.Ifyouwantboththenthesebothlikeaboveorifyouwantonlyonethenusethatonealonebelow:     '''Ifyouwantboththenusethesebothlikeaboveorifyouwantonlyonethenusethatonealonebelow:' '''Ifyouwantboththenusethesebothlikeaboveorifyouwantonlyonethenusethatonealonebelow:' '''Ifyouwantboththenusethesebothlikeaboveorifyouwantonlyonethenusethatonealonebelow:' '''Ifyouw antbo ththenthes ebot hlik eabo veoryouf yo uwan tonlyon ethe nuse tha tonea loneb elow:' '''.Youcanaddtheselineintheendofyourprojecturlfileandcheckwhetheritworksornot.'''ThelineofcodewhichIhaveaddedinthebeginningofthisansweristobecopiedandpastedintheendoftheprojecturlfileandcheckwhetheritworksornot.'''ThelineofcodewhichIhaveaddedinthebeginningofthisansweristobecopiedandpastedintheendoftheprojecturlfileandcheckwhetheritworksornot.'''ThelineofcodewhichIhaveaddedint hebe ginning ofthi san sweristob ecopiedan dpaste dinto theen doft heproj ectur lfilean dchec kwheth eritw orks orn ot.'''.Youcanaddtheselineatthetopoftheprojecturlfilebutmake surethatyoudon'taddanyotherlinelikefromdjangoimport*orthedjangorestframeworksocialauthappconfigimportAppConfigorthedjangorestframeworksocialauthmiddlewareimportSocialAuthExceptionMiddlewareorthedjangorestframeworksocialauthpipelineimportassociatebyemaildefaultasbyemaildefaultorthedjangorestframeworksocialauthpipelineimportdisconnectdefaultasdisconnectdefaul tord jango restf ramework social auth pipeline import getusername default as get username default ord jango restf ramework social auth pipeline import load extra data default as load extra data default ord jango restf ramework social auth pipeline import logout defaul tas logout defaul tord jango restf ramework social auth pipeline import mail validator default as mail validator default ord jango restf ramework social auth pipeline import redirect associate by email default as redirect associate by email defaul tord jango restf ramework social auth pipeline import request avatar from third party service as request avatar from third party service ord dj ango res tfra mewor ksocia lauth pipelin eimp ort selec tuserif alreadyexist sdefau ltas select userif already exists defaul tord dj ango res tfra mewor ksocia lauth pipelin eimp ort setusernamefromemaildefaultassetusernamefromemaildefaultordjangorestframeworksocialauthpipelineimportsetsignupfieldsdefaultassetsignupfieldsdefaultorddjangorestframeworksocialauthstorageclassOAUTH1AUTHENTICATIONFAILEDEXCEPTIONORDJANGORESTFRAMEWORKSOCIALAUTHSOCIALAPPORDJANGORESTFRAMEWORKSOCIALAUTHSOCIALAPPCONFIGORDJANGORESTFRAMEWORKSOCIALAUTHSOCIALAPPCONFIGCLASSESORDJANGORESTFRAMEWORKSOCIALAUTHSOCIALAPPFACTORYORDJANGORESTFRAMEWORKSOCIALAUTHSOCIALAPPMANAGERORDDJANGOIMPORTERIMPORTERERRORORTDATETIMEIMPORTDATETIMEORTIMECOMPARISONNOTSUPPORTEDBETWEENINSTANCESOFDATETIMEANDTZINFOORTIMEPARSEERRORORTZINFOSUBSTITUTIONSUBSTITUTIONNOTPERMITTEDINTHISSCOPEORTZINFOSUBSTITUTIONSUBSTITUTIONNOTPERMITTEDINTHISSCOPEORTZINFOSUBSTITUTIONSUBSTITUTIONNOTPERMITTEDINTHISSCOPEORTZINFOSUBSTITUTIONSUBSTITUTIONNOTPERMITTEDINTHISSCOPEORTZINFOSUBS T IT UTI ONSU B ST IT UT IO NN OT PE RM IT TE D IN TH IS SC OP E OR T Z INF OS UBS T IT UT IO NSU B ST IT UT IO NN OT PE RM IT TE D IN TH IS SC OP E OR T Z INF OS UBS T IT UT IO NSU B ST IT UT IO NN OT PE RM IT TE D IN TH IS SC OP E OR T Z INF OS UBS T IT UT IO NSU B ST IT UT IO NN OT PE RM IT TE D IN TH IS SC OP E OR DJ AN GO RES TF RA ME WOR K SOC IA L AUT H SOC IA L APP CON FI G CL AS SE S OR DJ AN GO RES TF RA ME WOR K SOC IA L AUT H SOC IA L APP CON FI G CL AS SE S OR DJ AN GO RES TF RA ME WOR K SOC IA L AUT H SOC IA L APP CON FI G CL AS SE S OR DJ AN GO RES TF RA ME WOR K SOC IA L AUT H SOC IA L APP CON FI G CL AS SE S O R D J A NG O R ES T FR AM EWO RK SO CIA LAU TH

SOC IA L AP P CON FI G CL AS SE S અથવા DJ AN GO RES TF RA ME WOR K SOC IA L AUT H SOC IA L APP CON FI G CL AS SE S અથવા DJ AN GO RES TF RA ME WOR K SOC IA L AUT H SOC IA L APP CON FI G CL AS SE S અથવા DJ AN GO RES TF RA ME WOR K SOC IA L AUT H SOC IA L APP CON FI G CL AS SE SORDJA NG અથવા ES T FR AM EWO RK SO CIA LAU TH SO CIA LA PP CO NF IG C LA SS ES અથવા DJA NG અથવા ES T FR AM EWO RK SO CIA LAU TH SO CIA LA PP CO NF IG C LA SS ES અથવા DJA NG અથવા ES T FR AM EWO RK SO CIA LAU TH SO CIA LA PP CO NF IG C LA SS ES અથવા DJA NG અથવા ES T FR AM EWO RK SO CIA LAU TH SO CIA LA PP CO NF IG C LA SS ES . તમે ટ્વેન્ટમીડિયા અને સ્ટેટિકફાઇ લેસપેથસેટિંગને સ્કિપ્ટીફાઇડ કરી શકો છો. ` સ્ટેટિક ` નો ઉપયોગ મીડિયા માટે ndstaticflespa માટે થાય છે

આરામ ફ્રેમવર્ક શું છે

રેસ્ટ ફ્રેમવર્ક એ Django એપ્લિકેશન છે જે તમને API અને વેબ સેવાઓ બનાવવામાં મદદ કરે છે. તે તમારા API ને બનાવવા, મેનેજ કરવા અને સુરક્ષિત કરવાનું સરળ બનાવવા માટે સાધનોનો સમૂહ પ્રદાન કરે છે.

oauth2 શું છે

OAuth2 એ વેબ પર સંસાધનોની ઍક્સેસને અધિકૃત કરવા માટેનો પ્રોટોકોલ છે. તે તૃતીય-પક્ષ એપ્લિકેશનો, જેમ કે સામાજિક નેટવર્ક્સ અથવા ઈ-કોમર્સ પ્લેટફોર્મ, વપરાશકર્તાઓને પ્રમાણિત કરવા અને સંસાધનો માટેની તેમની વિનંતીઓને અધિકૃત કરવાની મંજૂરી આપે છે.

સંબંધિત પોસ્ટ્સ:

પ્રતિક્રિયા આપો