2012/4/3 Matheus Ashton <matheu...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/ywPX8VH5CUQJ.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
2012/4/4 Matheus Ashton <matheu...@gmail.com>:
> urls.py:
>
> urlpatterns = patterns('',
> url(r'^/login$', LoginView.as_view()),
> url(r'^$', HomeView.as_view(), {}, 'home'),
> )
>
More simple way is using decorator for checking if user is authorized.
Add next string to your urls.py
# import decorator functionality
from django.contrib.auth.decorators import login_required
# import your views
from home.views import HomeView
final urls.py is :
from django.conf.urls.defaults import patterns, include, url
from django.contrib.auth.decorators import login_required
from home.views import HomeView
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
(r'^login/', 'django.contrib.auth.views.login', {'template_name':
'login.html'}),
(r'^$', login_required(HomeView.as_view())),
)
First line is mean that default djano auth mechanism is used for
checking user's auth.
Socond line means : each request is passed to HomeView but should
be authorized. If user is not authorized then redirect to login
windows should be .
As result your views.py should be :
from django.views.generic import TemplateView
# Create your views here.
class HomeView(TemplateView):
template_name='home.html'
Only three lines of the code !
You dont need more!
Thanks,
Serge
if in urls.py you replace
(r'^$', login_required(HomeView.as_view())),
with
(r'^$', login_required(TemplateView(template_name='home.html').as_view())),
you don't need any HomeView class!
--
Javier
2012/4/4 Javier Guerra Giraldez <jav...@guerrag.com>:
2012/4/5 Matheus Ashton <matheu...@gmail.com>: