already logged in users

15 views
Skip to first unread message

Luterien

unread,
Apr 19, 2011, 12:46:45 PM4/19/11
to Django users
Hello. I'm working on a django project and now i'm writing
register,login and logout pages. I dont want already logged in users
to access register or login pages. Is it possible to do that on the
template side or do i need to modify my login view ?

Any help appreciated!
Thanks

Oleg Lomaka

unread,
Apr 19, 2011, 12:51:48 PM4/19/11
to django...@googlegroups.com
{% if user.is_authenticated %}
  Hello, what are you doing here?
{% else %}
  Show login/registration form here
{% endif %}

Also I think doing it in templates is not right. It's job for decorators.

Luterien

unread,
Apr 19, 2011, 2:01:37 PM4/19/11
to Django users
I'm using the template method for now since i dont know much about
decorators. I tried using the decorators at contrib.auth.decorators
but it didnt work.

Thanks!

On Apr 19, 7:51 pm, Oleg Lomaka <oleg.lom...@gmail.com> wrote:
> {% if user.is_authenticated %}
>   Hello, what are you doing here?
> {% else %}
>   Show login/registration form here
> {% endif %}
>
> Also I think doing it in templates is not right. It's job for decorators.
>

Shawn Milochik

unread,
Apr 19, 2011, 2:18:54 PM4/19/11
to django...@googlegroups.com
On Tue, Apr 19, 2011 at 2:01 PM, Luterien <ugury...@gmail.com> wrote:
> I'm using the template method for now since i dont know much about
> decorators. I tried using the decorators at contrib.auth.decorators
> but it didnt work.

Doing something the wrong way you're comfortable with instead of
making yourself better at your job is really, really. bad. Just FYI. I
definitely wouldn't hire someone who cares that little about not doing
a horrible job that someone else is going to have to deal with in the
future.

You could also handle your original request in middleware. Technically
you could do it in a template by using the template language to write
JavaScript that would redirect, but that's still bad. The easiest way
is probably in the login view itself -- check if the request.user
either is_authenticated or is_anonymous and redirect as appropriate.

Shawn

Luterien

unread,
Apr 19, 2011, 2:49:57 PM4/19/11
to Django users
Thanks for the warning. But dont worry,i had no intention of leaving
it like that. As i said i dont know much about decorators,so i thought
it would be better to learn more about decorators before using them.
So i was reading the docs.

Yes,that is what i was looking for. I modified the login view as you
said and its working the way i want now. Thanks a lot!

On Apr 19, 9:18 pm, Shawn Milochik <sh...@milochik.com> wrote:

Shawn Milochik

unread,
Apr 19, 2011, 3:21:40 PM4/19/11
to django...@googlegroups.com
Cool. I understand putting a temporary solution in place to get the
job done sometimes.

Glad I could help.

Shawn

Reply all
Reply to author
Forward
0 new messages