python - Django 'next' redirect for log in and new user -
i have e-commerce website users can view ads without logging in. when want post ad re-directed login page, after successful login directed 'create ad' page. functionality working fine. problem when user re-directed log in page, , clicks on 'new user' , creates account, not redirected 'create ad' page after successful account creation.
my code looks far:
login.html:
#login form <form method="post" action="{% url 'login' %}"> {% csrf_token %} {% if request.get.next %} <input type="hidden" name="next" value={{ request.get.next }} /> {% endif %} <b>name:</b> {{ form.username }} <b>password:</b> {{ form.password }} <input type="submit" value="ok"> </form> # button redirect new account creation page <a href="{% url 'unauth_home_new' %}#section0"><button>new account</button></a> </div>
views.py:
def login(request, lang=none, *args,**kwargs): if request.user.is_authenticated(): if 'next' in request.post: return redirect(request.post['next']) return redirect("home") else: if request.method == 'post': if lang == 'ur': return log_me_in(request=request,template_name='login_ur.html') else: return log_me_in(request=request,template_name='login.html') else: if lang == 'ur': return log_me_in(request=request,template_name='login_ur.html') else: return log_me_in(request=request,template_name='login.html')
you need carry next on the create account page. after link create user page login, next lost on link. pass next login create user page.
you can tack on link create new account. might need on server side url in django in login view , send login template can add link.
Comments
Post a Comment