Hi I had a problem with display a form of login and register, please look
on it.
my template access_ownsite.html
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{% static
'ownsite/css/style.css' %}" />
</head>
<body>
{% block content %}
<div id="header">
{% if user.is_authenticated %}
<p>Jesteś zalogowany <a href='ownsite/my_view'>{{ user.username
}}</a></p>
<p><a href='/accounts/logout_view'>wyloguj</a></p>
{% else %}
<h2>Login</h2>
<form action = '/accounts/login_view/' method = 'post'>{% csrf_token %}
{{form.as_p}}
<input type='submit' value='Log' />
</form>
{% endif %}
</div>
<div id="content">
<div id="left_content">
{% block logout_msg %}
<p> {{ info }} </p>
<p>Nikt nie jest zalogowany w tym momencie.</p>
{% endblock %}
</div>
<div id="right_content">
{% if user.is_authenticated == False %}
<h2>Register</h2>
<form action = '/accounts/register_user/' method = 'post'>{%
csrf_token %}
{{form.as_p}}
<input type='submit' value='Register' />
</form>
{% endif %}
</div>
</div>
<div id="footer">
<p>copyright © Dariusz Mysior</p>
</div>
{% endblock %}
</body>
</html>
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:
# Return an 'invalid login' error message.
...
form = AuthenticationForm()
args = {}
args.update(csrf(request))
args['form']= AuthenticationForm()
return render_to_response('ownsite/access_ownsite.html',
args)#accounts/login.html
def my_view(request):
return render_to_response('accounts/my_view.html', {'username':
request.user.username,'user': request.user })
def register_user(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/accounts/register_success')
args = {}
args.update(csrf(request))
args['form']= UserCreationForm()
return render_to_response('accounts/register_user.html', args)
def register_success(request):
return render_to_response('accounts/register_success.html')
def logout_view(request):
logout(request)
return render_to_response('accounts/logout_view.html', {'info': 'Właśnie
się wylogowałeś.',})
--
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 [email protected].
To post to this group, send email to [email protected].
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/ef8af2cd-aad4-4faa-8eec-dca903187348%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.