On 12.05.2008, at 20:59, M.Ganesh wrote:

>
> Adi Jörg Sieker wrote:
>>
>> On 12.05.2008, at 15:13, M.Ganesh wrote:
>>
>>> Thanks Ronny for your response, however this doesn't answer my
>>> requirement. Probably I've to state my requirement more clearly.   
>>> I have
>>> various pages for general viewing where authentication is not  
>>> required.
>>> But if a user decides to add a record, he has to first login. I  
>>> take him
>>> to a login page for that. After he logs in I want to bring him  
>>> back to
>>> the same page. Note that a user can come to the login page from  
>>> any of
>>> the different pages. Hence the 'previous page' is not always the  
>>> same.
>>>
>>> Thanks in advance for any pointers
>>>
>> If you are using contrib.auth and it's login view. Then just pass  
>> it a
>> request variable called next with the url you want it to redirect to
>> after successful login or even better use the login_required  
>> decorator
>> that does it all for you.
>> See also the fine documentation
>> at 
>> http://www.djangoproject.com/documentation/authentication/#the-login-required-decorator
>>
>> Regards
>>   adi
> Thanks adi, but I am trying to use my own loginpage
>
but the idea is the same.

def login_view(request, next_url_from_page):
        if request.method == 'POST':
                do your login stuff
                 if user is logged in:
                        return HttpResponseRedirect(request.POST['next_url'])

        return direct_to_template(request, 'login.html', {'form': login_form,  
'next_url_from_page' : next_url_from_page })

in your login template:
<form>

<input type="hidden" name="next_url_from_form"  
value="{{next_url_from_page}}"
</form


your view that needs login:
def view_which_needs_login(request, *args, **kwargs):
        if user not logged in:
                        return HttpResponseRedirect("/your_login_page?next= 
%s" %(request.path))



I hope that helps.

Regards
    Adi




> Regards Ganesh
>
>
> 
--
Adi J. Sieker         mobile: +49 - 178 - 88 5 88 13
Freelance developer   skype:  adijsieker
SAP-Consultant        web:    http://www.sieker.info/profile
                       openbc: https://www.openbc.com/hp/ 
AdiJoerg_Sieker/




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to