开发者

Problem with redirecting to previous page after login in

With this code: urls.py

               url(r'^login/',
                   "django.contrib.auth.views.login"),

and tamplate like that:

<a href="{% url django.contrib.auth.views.login %}?next={{request.path}}">Login</a>

which is redirecting to page with this code:

      {% if not user.is_authenticated %}
      <form method="post" action="">{% csrf_token %}
          {{ form.as_p }}
        <input type="submit" value="Zaloguj" />
        <input type="hidden" name="next" value="" />
      </form>
      {% else %}
      <h1>Już jestes zalogowany chujku</h1>
      {% endif %}

I have context process开发者_C百科or 'django.core.context_processors.request' but after login in I am redirected to

accounts/profile/

When I am on login page url is: /accounts/login/?next=/gallery/newest/. More, after login in it loged me in but I am still in /accounts/login/?next=/gallery/newest/1/. Have I bugs in this code or answer is laying somewhere else?


Just remove <input type="hidden" name="next" value="" /> from your form, it makes django think that next variable is empty.


Finally i found answer. I think that this code did not use my own login.html template (but if i am wrong, please correct me):

url(r'^login/',
   "django.contrib.auth.views.login")

I change it to:

               url(r'^login/',
                   "django.contrib.auth.views.login", {'template_name': 'login.html'}),

Then I change my login.html tempalate code to:

  <form method="post" action="">{% csrf_token %}
      {{ form.as_p }}
    <input type="submit" value="Zaloguj" /> 
    <input type="hidden" name="next" value="{{ next }}" />

  </form>

I don't have the deeper meaning of what happend but this code which I copied here is working. Thanks for all for suggestions. It helps me to find answer and give a little better understanding of some things.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜