{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'accounts/css/style.css' %}" />
{% block content %}
{% if user.is_authenticated %}
<p>Jesteś zalogowany {{ username }}</p>
{% else %}
<h2>Strona główna</h2>
<a href='/accounts/login_view'>logowanie</a>
<a href='/accounts/register_user'>rejestracja</a>
{% endif %}
{% endblock %}
from django.shortcuts import render_to_response
def index(request):
return render_to_response('index.html', {'username': request.user.username})
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from django.shortcuts import render_to_response
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('accounts/login.html', args)
def my_view(request):
return render_to_response('accounts/my_view.html', {'username': request.user.username})
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(request):
pass
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'accounts/css/style.css' %}" />
{% block content %}
<h2>My profile</h2>
<p>Witaj {{ username }}</p>
{% endblock %}
def index(request):
return render_to_response('index.html', {'username': request.user.username,
'user':request.user})
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'accounts/css/style.css' %}" />
{% block content %}
{% if user.is_authenticated %}
<p>Jesteś zalogowany {{ user.username }}</p>
{% else %}
<h2>Strona główna</h2>
<a href='/accounts/login_view'>logowanie</a>
<a href='/accounts/register_user'>rejestracja</a>
{% endif %}
{% endblock %}
...