Re: Problem with login and register form
You should send both forms to the context, as in: args['form_login'] = AuthenticationForm() args['form_register'] = UserCreationForm() And change the template to the appropriate form names. Also, change {% if user.is_authenticated == False %} to {% if not user.is_authenticated %}. On Wednesday, November 25, 2015 at 4:24:29 PM UTC-2, Dariusz Mysior wrote: > > Before template access_ownsite.html I had separated on few templates like > login, register etc .html and it work's but now when I split it, a form is > not forward to access_ownsite.html > > W dniu wtorek, 24 listopada 2015 21:34:30 UTC+1 użytkownik Dariusz Mysior > napisał: >> >> Hi I had a problem with display a form of login and register, please look >> on it. >> >> my template access_ownsite.html >> >> {% load staticfiles %} >> >> >> >> >> {% block title %}{% endblock %} >> >> >> >> >> >> {% block content %} >> >> {% if user.is_authenticated %} >> Jesteś zalogowany {{ user.username >> }} >> wyloguj >> {% else %} >> Login >> {% csrf_token >> %} >> {{form.as_p}} >> >> >> {% endif %} >> >> >> >> {% block logout_msg %} >> {{ info }} >> Nikt nie jest zalogowany w tym momencie. >> {% endblock %} >> >> >> {% if user.is_authenticated == False %} >> Register >> {% >> csrf_token %} >> {{form.as_p}} >> >> >> {% endif %} >> >> >> >> copyright Dariusz Mysior >> >> {% endblock %} >> >> >> >> >> >> my view.py >> >> from django.contrib.auth.forms import UserCreationForm, AuthenticationForm >> from django.shortcuts import render_to_response, render >> from django.http import HttpResponseRedirect >> from django.core.context_processors import csrf >> from django.contrib.auth import authenticate, login, logout >> >> >> def login_view(request): >> if request.method == 'POST': >> username = request.POST['username'] >> password = request.POST['password'] >> user = authenticate(username=username, password=password) >> if user is not None: >> if user.is_active: >> login(request, user) >> return HttpResponseRedirect('/accounts/my_view') >> else: >> # Return a 'disabled account' error message >> ... >> else: >> >> >> ... > > -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/87bf02b7-ee2f-4046-9baa-20089f63aef6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Problem with login and register form
Before template access_ownsite.html I had separated on few templates like login, register etc .html and it work's but now when I split it, a form is not forward to access_ownsite.html W dniu wtorek, 24 listopada 2015 21:34:30 UTC+1 użytkownik Dariusz Mysior napisał: > > Hi I had a problem with display a form of login and register, please look > on it. > > my template access_ownsite.html > > {% load staticfiles %} > > > > > {% block title %}{% endblock %} > > > > > > {% block content %} > > {% if user.is_authenticated %} > Jesteś zalogowany {{ user.username > }} > wyloguj > {% else %} > Login > {% csrf_token > %} > {{form.as_p}} > > > {% endif %} > > > > {% block logout_msg %} > {{ info }} > Nikt nie jest zalogowany w tym momencie. > {% endblock %} > > > {% if user.is_authenticated == False %} > Register > {% > csrf_token %} > {{form.as_p}} > > > {% endif %} > > > > copyright Dariusz Mysior > > {% endblock %} > > > > > > my view.py > > from django.contrib.auth.forms import UserCreationForm, AuthenticationForm > from django.shortcuts import render_to_response, render > from django.http import HttpResponseRedirect > from django.core.context_processors import csrf > from django.contrib.auth import authenticate, login, logout > > > def login_view(request): > if request.method == 'POST': > username = request.POST['username'] > password = request.POST['password'] > user = authenticate(username=username, password=password) > if user is not None: > if user.is_active: > login(request, user) > return HttpResponseRedirect('/accounts/my_view') > else: > # Return a 'disabled account' error message > ... > else: > > > ... -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/777e462c-1589-489b-bb0b-f4786cc81944%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Problem with login and register form
It's not fix a problem. W dniu wtorek, 24 listopada 2015 21:34:30 UTC+1 użytkownik Dariusz Mysior napisał: > > Hi I had a problem with display a form of login and register, please look > on it. > > my template access_ownsite.html > > {% load staticfiles %} > > > > > {% block title %}{% endblock %} > > > > > > {% block content %} > > {% if user.is_authenticated %} > Jesteś zalogowany {{ user.username > }} > wyloguj > {% else %} > Login > {% csrf_token > %} > {{form.as_p}} > > > {% endif %} > > > > {% block logout_msg %} > {{ info }} > Nikt nie jest zalogowany w tym momencie. > {% endblock %} > > > {% if user.is_authenticated == False %} > Register > {% > csrf_token %} > {{form.as_p}} > > > {% endif %} > > > > copyright Dariusz Mysior > > {% endblock %} > > > > > > my view.py > > from django.contrib.auth.forms import UserCreationForm, AuthenticationForm > from django.shortcuts import render_to_response, render > from django.http import HttpResponseRedirect > from django.core.context_processors import csrf > from django.contrib.auth import authenticate, login, logout > > > def login_view(request): > if request.method == 'POST': > username = request.POST['username'] > password = request.POST['password'] > user = authenticate(username=username, password=password) > if user is not None: > if user.is_active: > login(request, user) > return HttpResponseRedirect('/accounts/my_view') > else: > # Return a 'disabled account' error message > ... > else: > > > ... -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bdff446d-0050-40af-af62-11ac4f9df446%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Problem with login and register form
It's a good idea to use render() instead of render_to_response(), see https://docs.djangoproject.com/en/1.8/topics/http/shortcuts/#render. That will fix the issue with the CSRF token. render() takes the request as the first argument, and uses a RequestContext. This is needed to run the context processors, which add the csrf_token to the template. On Wednesday, November 25, 2015 at 7:05:26 PM UTC+1, Dariusz Mysior wrote: > > Hmm I forget about it but I change names on form_l and form_r and effect > is the same, I had also info > > > C:\Python34\lib\site-packages\django\template\defaulttags.py:66: >> UserWarning: A {% csrf_token %} was used in a template, but the context did >> not provide the value. This is usually cause >> d by not using RequestContext. >> "A {% csrf_token %} was used in a template, but the context " >> >> > W dniu wtorek, 24 listopada 2015 21:34:30 UTC+1 użytkownik Dariusz Mysior > napisał: >> >> Hi I had a problem with display a form of login and register, please look >> on it. >> >> my template access_ownsite.html >> >> {% load staticfiles %} >> >> >> >> >> {% block title %}{% endblock %} >> >> >> >> >> >> {% block content %} >> >> {% if user.is_authenticated %} >> Jesteś zalogowany {{ user.username >> }} >> wyloguj >> {% else %} >> Login >> {% csrf_token >> %} >> {{form.as_p}} >> >> >> {% endif %} >> >> >> >> {% block logout_msg %} >> {{ info }} >> Nikt nie jest zalogowany w tym momencie. >> {% endblock %} >> >> >> {% if user.is_authenticated == False %} >> Register >> {% >> csrf_token %} >> {{form.as_p}} >> >> >> {% endif %} >> >> >> >> copyright Dariusz Mysior >> >> {% endblock %} >> >> >> >> >> >> my view.py >> >> from django.contrib.auth.forms import UserCreationForm, AuthenticationForm >> from django.shortcuts import render_to_response, render >> from django.http import HttpResponseRedirect >> from django.core.context_processors import csrf >> from django.contrib.auth import authenticate, login, logout >> >> >> def login_view(request): >> if request.method == 'POST': >> username = request.POST['username'] >> password = request.POST['password'] >> user = authenticate(username=username, password=password) >> if user is not None: >> if user.is_active: >> login(request, user) >> return HttpResponseRedirect('/accounts/my_view') >> else: >> # Return a 'disabled account' error message >> ... >> else: >> >> >> ... > > -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e4504d21-0587-4ebf-8a76-a69aa1afaa81%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Problem with login and register form
Hmm I forget about it but I change names on form_l and form_r and effect is the same, I had also info C:\Python34\lib\site-packages\django\template\defaulttags.py:66: > UserWarning: A {% csrf_token %} was used in a template, but the context did > not provide the value. This is usually cause > d by not using RequestContext. > "A {% csrf_token %} was used in a template, but the context " > > W dniu wtorek, 24 listopada 2015 21:34:30 UTC+1 użytkownik Dariusz Mysior napisał: > > Hi I had a problem with display a form of login and register, please look > on it. > > my template access_ownsite.html > > {% load staticfiles %} > > > > > {% block title %}{% endblock %} > > > > > > {% block content %} > > {% if user.is_authenticated %} > Jesteś zalogowany {{ user.username > }} > wyloguj > {% else %} > Login > {% csrf_token > %} > {{form.as_p}} > > > {% endif %} > > > > {% block logout_msg %} > {{ info }} > Nikt nie jest zalogowany w tym momencie. > {% endblock %} > > > {% if user.is_authenticated == False %} > Register > {% > csrf_token %} > {{form.as_p}} > > > {% endif %} > > > > copyright Dariusz Mysior > > {% endblock %} > > > > > > my view.py > > from django.contrib.auth.forms import UserCreationForm, AuthenticationForm > from django.shortcuts import render_to_response, render > from django.http import HttpResponseRedirect > from django.core.context_processors import csrf > from django.contrib.auth import authenticate, login, logout > > > def login_view(request): > if request.method == 'POST': > username = request.POST['username'] > password = request.POST['password'] > user = authenticate(username=username, password=password) > if user is not None: > if user.is_active: > login(request, user) > return HttpResponseRedirect('/accounts/my_view') > else: > # Return a 'disabled account' error message > ... > else: > > > ... -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6538ba58-57c6-4c5c-8ebe-686ea85c184d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Problem with login and register form
You are using the same form for both register and login. Set different names for the forms in the template context. On Tuesday, November 24, 2015 at 6:34:30 PM UTC-2, Dariusz Mysior wrote: > > Hi I had a problem with display a form of login and register, please look > on it. > > my template access_ownsite.html > > {% load staticfiles %} > > > > > {% block title %}{% endblock %} > > > > > > {% block content %} > > {% if user.is_authenticated %} > Jesteś zalogowany {{ user.username > }} > wyloguj > {% else %} > Login > {% csrf_token > %} > {{form.as_p}} > > > {% endif %} > > > > {% block logout_msg %} > {{ info }} > Nikt nie jest zalogowany w tym momencie. > {% endblock %} > > > {% if user.is_authenticated == False %} > Register > {% > csrf_token %} > {{form.as_p}} > > > {% endif %} > > > > copyright Dariusz Mysior > > {% endblock %} > > > > > > my view.py > > from django.contrib.auth.forms import UserCreationForm, AuthenticationForm > from django.shortcuts import render_to_response, render > from django.http import HttpResponseRedirect > from django.core.context_processors import csrf > from django.contrib.auth import authenticate, login, logout > > > def login_view(request): > if request.method == 'POST': > username = request.POST['username'] > password = request.POST['password'] > user = authenticate(username=username, password=password) > if user is not None: > if user.is_active: > login(request, user) > return HttpResponseRedirect('/accounts/my_view') > else: > # Return a 'disabled account' error message > ... > else: > > > ... -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/44800974-3d87-411c-848a-03050edb6daf%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.