Django password reset issue - python

I saw a tutorial and I implemented a password resetter through email. The email sending part works fine and I get the email after clicking it I get redirected to reset password page. But after I give the new password and click Submit it gets redirected to the login page but the password is not getting reset.
urls.py
path('password-reset/',auth_views.PasswordResetView.as_view(template_name='password_reset.html'),name='password_reset'),
path('password-reset/done/',auth_views.PasswordResetDoneView.as_view(template_name='password_reset_done.html'),name='password_reset_done'),
path('password-reset-confirm/<uidb64>/<token>/',auth_views.PasswordResetConfirmView.as_view(template_name='password_reset_confirm.html'),name='password_reset_confirm'),
path('password-reset-complete/',auth_views.PasswordResetCompleteView.as_view(template_name='password_reset_complete.html'),name='password_reset_complete'),
password_reset_confirm.py
{% extends "base.html" %}
{% load static %}
{% block head_block %}
<link rel="stylesheet" type="text/css" href="{% static 'index.css' %}">
{% endblock head_block %}
{% block body_block %}
{% csrf_token %}
<form method="post" action="{% url 'reg_sign_in_out:user_login' %}">
{% csrf_token %}
<input type="password" name="" id="">
<input type="submit" value="Reset">
</form>
{% endblock %}
Any idea where the problem is?

I think that you have to put in your form the action of your post, for example if you have to go to the password-reset/done/ URL, you have to add
<form method="post" action="password-reset/done/" >
{% csrf_token %}
<input type="password" name="" id="">
<input type="submit" value="Reset">
</form>
Because if you don't put the action, it will redirect to the same page

The problem was a redirecting issue. Its fixed.

Related

Failing to submit to a link page

When i click on the submit button i am getting the 404 error, i want to submit to the "new_search"
{% extends 'base.html' %}
{% block content %}
<form action="{ % url 'new_search' %}" method="post">
{% csrf_token %}
<input type="text" name="search" value="search" placeholder="search">
<input type="submit" name="submit">
</form>
{% endblock content %}
page
There is a typo in your code, replace:
{ % url 'new_search' %}
with
{% url 'new_search' %}

i cant login to my Django User credentials

I following the tutorial of https://developer.mozilla.org/id/docs/Learn/Server-side/Django/Authentication
I already following that site step by step and now i have reached Login Template stage, but i've some problem that i cant login, Django tell me that 'Your username and password didn't match. Please try again. ' even though I login using valid credentials
my login.html
{% load static %}
<html>
<head>
<title>Login Page</title>
<link rel="stylesheet" type="text/css" href="{% static 'style login.css' %}">
</head>
<body>
{% if form.errors %}
<p>Your username and password didnt match. Please try again.</p>
{% endif %}
{% if next %}
{% if user.is_authenticated %}
<p>Your account doesnt have access to this page. To proceed,
please login with an account that has access.</p>
{% else %}
<p>Please login to see this page.</p>
{% endif %}
{% endif %}
<div class="loginbox">
<img src="{% static 'avatar.png' %}" class="avatar">
<h1>Login Here</h1>
<form method="post" action="{% url 'login'%}">
{% csrf_token %}
<p>Username</p>
<input type="text" name="" placeholder="Enter Username">
<p>Password</p>
<input type="password" name="" placeholder="Enter Password">
<input type="submit" name="" value="{{ next }}">
Dont have an account
</form>
</div>
</body>
</html>

Invalid Endblock tag in django

I am receiving an error message when I go to one of my pages in my Django project, as it is saying that the End-block tag is invalid (asks whether I remembered to register or load). The error looks like this:
My code for this template - (login.html) - is below:
{% extends "learning_logs/base.html" %}
{% block content %}
{% if form.errors %}
<p>Your username and password didn't match. Please try again.'</p>
{% endif %}
<form method="post" action="{% url 'users:login' %}">
{% csrf_token %}
{{ form.as_p }}
<button name="sumbit">log in</button>
<input type="hidden" name="next" value="{% extends 'learning_logs/index.html' %}" />
</form>
{% endblock content %}
I am very confused, and I am wondering whether anyone knows what the problem is?
Thanks
Milo
<input type="hidden" name="next" value="{% extends 'learning_logs/index.html' %}" />
Above line contains {% extends .... %}. To prevent being interpreted as a extends tag, use templatetag tag:
<input type="hidden" name="next" value="{% templatetag openblock %} extends 'learning_logs/index.html' {% templatetag closeblock %}" />
use {% endblock %} instead o f {% endblock content %}
for me it was wrongly auto-formatted html file. Check auto-formatting for html files.

Django password is not changed

I don't know what I'm doing wrong, but when I try to change the password it doesn't change it and it doesn't give any errors.
urls.py
from django.contrib.auth.views import logout,password_change,password_change_done
...
url(r'^change_password/?$',password_change, name='password_change'),
url(r'^password_changed/?$',password_change_done, name='password_change_done'),
url(r'^logout/?$',logout, name='logout'),
password_change_form.html
<form action="{% url 'password_change_done' %}" method="post">
{% csrf_token %}
{% bootstrap_form form layout="inline" form_group_class="form-group col-md-6" %}
<div class="clearfix"></div>
{% buttons %}
<button type="submit" name="save" class="btn btn-primary">{% bootstrap_icon "plus" %} {% trans 'save' %}</button>
{% endbuttons %}
</form>
When I click on save, it shows the template "password_change_done.html" but the password hasn't been changed. However, there are no errors in the console and I don't know what fails.
Thank you all
The form action should be password_change not password_change_done:
<form action="{% url 'password_change' %}" method="post">
Django will automatically do the redirect to password_change_done for you once the password change is successful.

form.has_errors tag not working

Im using Django 1.2.3. I have login functionality in my site using django.contrib.auth.views.login. The user is able to login after entering correct username and password. But, form.has_errors is not working i.e. if the login credentials entered are incorrect i dont see the error message. My login.html in templates/registration is as follows :
<html>
<head>
<title>Login</title>
</head>
<body>
<h1>User Login</h1>
{% if form.has_errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
<form method="post" action=".">
{% csrf_token %}
<p><label for="id_username">Username:</label> {{ form.username }}</p>
<p><label for="id_password">Password:</label> {{ form.password }}</p>
<input type="hidden" name="next" value="/" />
<input type="submit" value="login" />
</form>
</body>
</html>
Any way to fix this problem?
Please Help
Thank You.
A Form object does have an errors attribute, read the docs for more information:
{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
Apparently has_errors was valid in Django 0.95 but not from at least 1.0 upwards (as it was replaced with errors). [reference]

Categories