Re: Problem with seassion

2015-11-13 Thread Dariusz Mysior
Ok I have it! :)

views.py

def index(request):
return render_to_response('index.html', {'username': request.user.username,
 'user':request.user})


index.html

{% load staticfiles %}
 

 
{% block content %}
{% if user.is_authenticated %}
Jesteś zalogowany {{ user.username }}
{% else %}
Strona główna
logowanie
rejestracja
 
{% endif %}
 
 
{% endblock %}




W dniu piątek, 13 listopada 2015 09:59:04 UTC+1 użytkownik Dariusz Mysior 
napisał:
>
> In the application accounts have everything that regards registration and 
> login and beyond this application in the project folder I have index.html to 
> the home page where I have links to login and registration forms, I would 
> like to index.html in some way to provide request.user.username that 
> instead of these two URLs I showed the message that I'm logged in.
>
> How can I request.user.username application file accounts views.py move to 
> file views.py main project? : /
>
> I paste here all what I already have
>
> index.html from the root folder of the project
>
> {% load staticfiles %}
>  
> 
>  
> {% block content %}
> {% if user.is_authenticated %}
> Jesteś zalogowany {{ username }}
> {% else %}
> Strona główna
> logowanie
> rejestracja
> {% endif %}
>  
>  
> {% endblock %}
>
>
> views.py from the root folder of the project
>
> from django.shortcuts import render_to_response
>  
> def index(request):
> return render_to_response('index.html', {'username': 
> request.user.username})
>
>
> accounts/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, 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
>
> ...

-- 
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/1d6b8bd8-34b4-40d0-8462-58730888c415%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Problem with seassion

2015-11-13 Thread Dariusz Mysior
In the application accounts have everything that regards registration and 
login and beyond this application in the project folder I have index.html to 
the home page where I have links to login and registration forms, I would 
like to index.html in some way to provide request.user.username that instead of 
these two URLs I showed the message that I'm logged in.

How can I request.user.username application file accounts views.py move to 
file views.py main project? : /

I paste here all what I already have

index.html from the root folder of the project

{% load staticfiles %}
 

 
{% block content %}
{% if user.is_authenticated %}
Jesteś zalogowany {{ username }}
{% else %}
Strona główna
logowanie
rejestracja
{% endif %}
 
 
{% endblock %}


views.py from the root folder of the project

from django.shortcuts import render_to_response
 
def index(request):
return render_to_response('index.html', {'username': request.user.username})


accounts/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, 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


accounts/my_view

{% load staticfiles %}
 

 
{% block content %}
My profile
Witaj {{ username }}
{% endblock %}



-- 
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/cbe04e43-5e3c-40ad-a6a1-9c9a1d985ece%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.