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 %}
<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 %}
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 %}
<link rel="stylesheet" type="text/css" href="{% static 'accounts/css/style.css'
%}" />
{% block content %}
<h2>My profile</h2>
<p>Witaj {{ username }}</p>
{% 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 [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/cbe04e43-5e3c-40ad-a6a1-9c9a1d985ece%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.