Question

Thanks In Advance.

I am facing an Issue in one of my Django Website. Here an authenticated user can access the Registration Page. But the client raised it as an issue. So I have tried to rectify that Issue and ended up with the following Solution.

Is it a good solution? Or how can I make it good?

The Process should be like this, when a loginned user try to access the Registration Page, he should be automatically Logged Out from the Site and then redirected to the Registration Page.

My code is

def user_signup(request, template_name='profiles/profile_register_form.html'):
if request.user.is_authenticated():
    return custom_logout(request, next_page = "/accounts/register/")


def custom_logout(request, next_page='/'):
try:
    language = request.session['django_language']
except:
    language = False
response = logout(request, next_page=next_page)
if language:
    request.session['django_language'] = language
return response
Was it helpful?

Solution

Your method was correct. It will save the current language session and will do the exact process you need

OTHER TIPS

if i understood your question then

why custom_logout

you can call directly django logout like

if request.user.is_authenticated():
    logout(request)
    return HttpResponseRedirect('/login/')  # whatever you register page 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top