Thanks for both advice. I am not advanced programmer sow I use the simplest 
solution on this moment this first one Andréas Kühne. Thanks it works!

W dniu czwartek, 12 listopada 2015 08:46:06 UTC+1 użytkownik Dariusz Mysior 
napisał:
>
> I am using Django 1.8 with Python 3.4 I had no idea why my template 
> doesn't show my username on template profile.html :/
>
>
> profile.py
>
>
> {% load staticfiles %}
>
> <link rel="stylesheet" type="text/css" href="{% static 
> 'accounts/css/style.css' %}" />
>
> {% block content %}
> <h2>My profile</h2>
> <p>{{ request.user.username }}</p>
> {% endblock %}
>
>
> views.py
>
>
> 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
>
>
> 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/profile')
>             else:
>                 # Return a 'disabled account' error message
>                 ...
>                 pass
>         else:
>             # Return an 'invalid login' error message.
>             pass
>     form = AuthenticationForm()
>     args = {}
>     args.update(csrf(request))
>     args['form']= AuthenticationForm()
>     return render_to_response('accounts/login.html', args)
>
> def my_view(request):
>     username = request.POST['username']
>     password = request.POST['password']
>     user = authenticate(username=username, password=password)
>     if user is not None:
>         print(request.user)
>         if user.is_active:
>             login(request, user)
>             return HttpResponseRedirect('/accounts/profile')
>         else:
>             # Return a 'disabled account' error message
>             ...
>     else:
>         # Return an 'invalid login' error message.
>         ...
> def profile(request):
>     username = request.user.username
>     return render_to_response('accounts/profile.html', 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')
>
>
>
>

-- 
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/2b355828-bbfd-4ffd-a8c4-ab0001f42f68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to