Problems with Django logout on URLs










0














I'm beginner with Django and I've resolved my problem yet, but I want to understand...



I've a login page on my app and a logout page, here is it:



urls.py:



url('deconnexion', views.logout, name='deconnexion'),
url('connexion', views.connexion, name='connexion'),


views.py:



def connexion(request):
error = False

if request.method == "POST":
form = ConnexionForm(request.POST)

if form.is_valid():

username = form.cleaned_data["username"]
password = form.cleaned_data["password"]
user = authenticate(username=username, password=password)

if user:
login(request, user)
else:
error = True
else:
form = ConnexionForm()

return render(request, 'dashboard/connexion.html', locals())


@login_required(login_url='/dashboard/connexion/')
def logout(request):
django_logout(request)
return redirect(reverse(connexion))


If I change place for url: connexion in place of deconnexion, my script doesn't work... I don't logout me and I'm redirected on the connexion page which is being connected...



If somebody have an idea?



P.S.: Sorry for my poor English, I'm French... And French with English.... we all know it's complicated... sorry ;)










share|improve this question























  • You can use Django User Authentication, then you don't have to handle these auth operations yourself.
    – MD. Khairul Basar
    Nov 13 '18 at 9:38











  • Please clarify: what do you mean by "change place"? in urls.py or in views.py? Ho and bienvenue to StackOverflow :)
    – Régis B.
    Nov 13 '18 at 9:44










  • I don't really understand what you have done, but the problem is probably in your URLs; you should either use anchors before and after the patterns (r"^connexion$") or use path() instead of url().
    – Daniel Roseman
    Nov 13 '18 at 9:45











  • Thanks a lot for your help and your welcome message :) Indeed, it's in my url, Thanks @Régis B. MD. Khairul Basar and Daniel Roseman for your help, it was my anchors... I'm a noob XD
    – Baptiste Guillaud
    Nov 14 '18 at 12:57










  • The problem was probably due to the fact that the r"connexion" regex matches the "deconnexion" string.
    – Régis B.
    Nov 14 '18 at 15:26















0














I'm beginner with Django and I've resolved my problem yet, but I want to understand...



I've a login page on my app and a logout page, here is it:



urls.py:



url('deconnexion', views.logout, name='deconnexion'),
url('connexion', views.connexion, name='connexion'),


views.py:



def connexion(request):
error = False

if request.method == "POST":
form = ConnexionForm(request.POST)

if form.is_valid():

username = form.cleaned_data["username"]
password = form.cleaned_data["password"]
user = authenticate(username=username, password=password)

if user:
login(request, user)
else:
error = True
else:
form = ConnexionForm()

return render(request, 'dashboard/connexion.html', locals())


@login_required(login_url='/dashboard/connexion/')
def logout(request):
django_logout(request)
return redirect(reverse(connexion))


If I change place for url: connexion in place of deconnexion, my script doesn't work... I don't logout me and I'm redirected on the connexion page which is being connected...



If somebody have an idea?



P.S.: Sorry for my poor English, I'm French... And French with English.... we all know it's complicated... sorry ;)










share|improve this question























  • You can use Django User Authentication, then you don't have to handle these auth operations yourself.
    – MD. Khairul Basar
    Nov 13 '18 at 9:38











  • Please clarify: what do you mean by "change place"? in urls.py or in views.py? Ho and bienvenue to StackOverflow :)
    – Régis B.
    Nov 13 '18 at 9:44










  • I don't really understand what you have done, but the problem is probably in your URLs; you should either use anchors before and after the patterns (r"^connexion$") or use path() instead of url().
    – Daniel Roseman
    Nov 13 '18 at 9:45











  • Thanks a lot for your help and your welcome message :) Indeed, it's in my url, Thanks @Régis B. MD. Khairul Basar and Daniel Roseman for your help, it was my anchors... I'm a noob XD
    – Baptiste Guillaud
    Nov 14 '18 at 12:57










  • The problem was probably due to the fact that the r"connexion" regex matches the "deconnexion" string.
    – Régis B.
    Nov 14 '18 at 15:26













0












0








0







I'm beginner with Django and I've resolved my problem yet, but I want to understand...



I've a login page on my app and a logout page, here is it:



urls.py:



url('deconnexion', views.logout, name='deconnexion'),
url('connexion', views.connexion, name='connexion'),


views.py:



def connexion(request):
error = False

if request.method == "POST":
form = ConnexionForm(request.POST)

if form.is_valid():

username = form.cleaned_data["username"]
password = form.cleaned_data["password"]
user = authenticate(username=username, password=password)

if user:
login(request, user)
else:
error = True
else:
form = ConnexionForm()

return render(request, 'dashboard/connexion.html', locals())


@login_required(login_url='/dashboard/connexion/')
def logout(request):
django_logout(request)
return redirect(reverse(connexion))


If I change place for url: connexion in place of deconnexion, my script doesn't work... I don't logout me and I'm redirected on the connexion page which is being connected...



If somebody have an idea?



P.S.: Sorry for my poor English, I'm French... And French with English.... we all know it's complicated... sorry ;)










share|improve this question















I'm beginner with Django and I've resolved my problem yet, but I want to understand...



I've a login page on my app and a logout page, here is it:



urls.py:



url('deconnexion', views.logout, name='deconnexion'),
url('connexion', views.connexion, name='connexion'),


views.py:



def connexion(request):
error = False

if request.method == "POST":
form = ConnexionForm(request.POST)

if form.is_valid():

username = form.cleaned_data["username"]
password = form.cleaned_data["password"]
user = authenticate(username=username, password=password)

if user:
login(request, user)
else:
error = True
else:
form = ConnexionForm()

return render(request, 'dashboard/connexion.html', locals())


@login_required(login_url='/dashboard/connexion/')
def logout(request):
django_logout(request)
return redirect(reverse(connexion))


If I change place for url: connexion in place of deconnexion, my script doesn't work... I don't logout me and I'm redirected on the connexion page which is being connected...



If somebody have an idea?



P.S.: Sorry for my poor English, I'm French... And French with English.... we all know it's complicated... sorry ;)







django logout






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 9:55









Régis B.

5,83533465




5,83533465










asked Nov 13 '18 at 9:34









Baptiste GuillaudBaptiste Guillaud

1




1











  • You can use Django User Authentication, then you don't have to handle these auth operations yourself.
    – MD. Khairul Basar
    Nov 13 '18 at 9:38











  • Please clarify: what do you mean by "change place"? in urls.py or in views.py? Ho and bienvenue to StackOverflow :)
    – Régis B.
    Nov 13 '18 at 9:44










  • I don't really understand what you have done, but the problem is probably in your URLs; you should either use anchors before and after the patterns (r"^connexion$") or use path() instead of url().
    – Daniel Roseman
    Nov 13 '18 at 9:45











  • Thanks a lot for your help and your welcome message :) Indeed, it's in my url, Thanks @Régis B. MD. Khairul Basar and Daniel Roseman for your help, it was my anchors... I'm a noob XD
    – Baptiste Guillaud
    Nov 14 '18 at 12:57










  • The problem was probably due to the fact that the r"connexion" regex matches the "deconnexion" string.
    – Régis B.
    Nov 14 '18 at 15:26
















  • You can use Django User Authentication, then you don't have to handle these auth operations yourself.
    – MD. Khairul Basar
    Nov 13 '18 at 9:38











  • Please clarify: what do you mean by "change place"? in urls.py or in views.py? Ho and bienvenue to StackOverflow :)
    – Régis B.
    Nov 13 '18 at 9:44










  • I don't really understand what you have done, but the problem is probably in your URLs; you should either use anchors before and after the patterns (r"^connexion$") or use path() instead of url().
    – Daniel Roseman
    Nov 13 '18 at 9:45











  • Thanks a lot for your help and your welcome message :) Indeed, it's in my url, Thanks @Régis B. MD. Khairul Basar and Daniel Roseman for your help, it was my anchors... I'm a noob XD
    – Baptiste Guillaud
    Nov 14 '18 at 12:57










  • The problem was probably due to the fact that the r"connexion" regex matches the "deconnexion" string.
    – Régis B.
    Nov 14 '18 at 15:26















You can use Django User Authentication, then you don't have to handle these auth operations yourself.
– MD. Khairul Basar
Nov 13 '18 at 9:38





You can use Django User Authentication, then you don't have to handle these auth operations yourself.
– MD. Khairul Basar
Nov 13 '18 at 9:38













Please clarify: what do you mean by "change place"? in urls.py or in views.py? Ho and bienvenue to StackOverflow :)
– Régis B.
Nov 13 '18 at 9:44




Please clarify: what do you mean by "change place"? in urls.py or in views.py? Ho and bienvenue to StackOverflow :)
– Régis B.
Nov 13 '18 at 9:44












I don't really understand what you have done, but the problem is probably in your URLs; you should either use anchors before and after the patterns (r"^connexion$") or use path() instead of url().
– Daniel Roseman
Nov 13 '18 at 9:45





I don't really understand what you have done, but the problem is probably in your URLs; you should either use anchors before and after the patterns (r"^connexion$") or use path() instead of url().
– Daniel Roseman
Nov 13 '18 at 9:45













Thanks a lot for your help and your welcome message :) Indeed, it's in my url, Thanks @Régis B. MD. Khairul Basar and Daniel Roseman for your help, it was my anchors... I'm a noob XD
– Baptiste Guillaud
Nov 14 '18 at 12:57




Thanks a lot for your help and your welcome message :) Indeed, it's in my url, Thanks @Régis B. MD. Khairul Basar and Daniel Roseman for your help, it was my anchors... I'm a noob XD
– Baptiste Guillaud
Nov 14 '18 at 12:57












The problem was probably due to the fact that the r"connexion" regex matches the "deconnexion" string.
– Régis B.
Nov 14 '18 at 15:26




The problem was probably due to the fact that the r"connexion" regex matches the "deconnexion" string.
– Régis B.
Nov 14 '18 at 15:26












1 Answer
1






active

oldest

votes


















0














As described in django documentations you can do like this:



from django.contrib.auth import logout

def logout_view(request):
logout(request)
return redirect(reverse(connexion))





share|improve this answer




















  • Thanks for this code !
    – Baptiste Guillaud
    Nov 14 '18 at 12:58










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277883%2fproblems-with-django-logout-on-urls%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














As described in django documentations you can do like this:



from django.contrib.auth import logout

def logout_view(request):
logout(request)
return redirect(reverse(connexion))





share|improve this answer




















  • Thanks for this code !
    – Baptiste Guillaud
    Nov 14 '18 at 12:58















0














As described in django documentations you can do like this:



from django.contrib.auth import logout

def logout_view(request):
logout(request)
return redirect(reverse(connexion))





share|improve this answer




















  • Thanks for this code !
    – Baptiste Guillaud
    Nov 14 '18 at 12:58













0












0








0






As described in django documentations you can do like this:



from django.contrib.auth import logout

def logout_view(request):
logout(request)
return redirect(reverse(connexion))





share|improve this answer












As described in django documentations you can do like this:



from django.contrib.auth import logout

def logout_view(request):
logout(request)
return redirect(reverse(connexion))






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 9:39









Hosein RemezanHosein Remezan

315414




315414











  • Thanks for this code !
    – Baptiste Guillaud
    Nov 14 '18 at 12:58
















  • Thanks for this code !
    – Baptiste Guillaud
    Nov 14 '18 at 12:58















Thanks for this code !
– Baptiste Guillaud
Nov 14 '18 at 12:58




Thanks for this code !
– Baptiste Guillaud
Nov 14 '18 at 12:58

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277883%2fproblems-with-django-logout-on-urls%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

Evgeni Malkin