why I can't get the PasswordResetDoneView page? - django

when I submit my Email form from PasswordResetView page the email appears via URL as following: http://127.0.0.1:8000/account/password-change/?email=medoabdin%40gmail.com and not directing me to PasswordResetDoneView page and I get no error.
how can I show PasswordResetDoneView message page
urls.py
from django.urls import path
from . import views
from django.contrib.auth.views import (
LoginView,
LogoutView,
PasswordResetView,
PasswordResetDoneView)
from django.urls import reverse_lazy
app_name = 'account'
urlpatterns = [
# /account/login/
path('login/', LoginView.as_view(template_name='account/login.html'), name='login'),
# /account/logout/
path('logout/', LogoutView.as_view(template_name='account/logout.html'), name='logout'),
# /account/register/
path('register/', views.register, name='register'),
# /account/view-profile/
path('view-profile/', views.view_profile, name='view_profile'),
# /account/password-change/
path('password-change/', PasswordResetView.as_view(template_name='account/password_change_view.html', success_url=reverse_lazy('account:password_change_done'), email_template_name='account/reset_password_email.html'), name='password_change'),
# /account/password-change/done/
path('password-chane/done/', PasswordResetDoneView.as_view(template_name='account/password_change_done.html'), name='password_change_done'),
]
password_change_done.html
{% extends 'base.html' %}
{% block title %} Success Message {% endblock %}
{% block body %}
{% if not user.is_authenticated %}
<div class="password-change-done">
<div class="container">
<h1 class="text-primary"> The Password Has Been Sent </h1>
<p class="lead text-success"> Check your email and following the rest of record until you can go back your own email. </p>
<p class="lead text-success"> You need to follow the instructions to get what you want. </p>
</div>
</div>
{% endif %}
{% endblock %}
password_change_view.html
{% extends 'base.html' %}
{% block title %} Chnage your Passowrd {% endblock %}
{% block body %}
{% if not user.is_authenticated %}
<div class="password-change">
<div class="container">
<div class="my-form">
<form class="post">
{{ form.as_p }}
<button type="submit" class="btn btn-success">Go</button>
</form>
</div>
</div>
</div>
{% endif %}
{% endblock %}
settings.py
urlpatterns = [
path('', include('index.urls')),
path('account/', include('account.urls')),
path('admin/', admin.site.urls),
path('', include('django.contrib.auth.urls')),
]

Put method="post" in form tag and also {% csrf_token %}, probably because of GET method same view is rendering and form_valid is not invoking.

Related

Page not found (404) Request Method:

please help me. I don't know why can't see the detail of product when i click a product. both first list work good just when i need to see detail of product in second list(filtered list) an 404 error shows.
thanks
here is my code below:
my urls:
from django.urls import path
from . import views
app_name = 'shop'
urlpatterns = [
path('', views.HomeView.as_view(), name='home'),
path('categories/<category>/', views.ProductListView.as_view(), name='product-list'),
path('categories/<int:pk>/', views.ProductDetailView.as_view(), name='product-detail'),
]
views:
from django.shortcuts import render, get_object_or_404, get_list_or_404
from django.views import generic
from .models import Category, Product
class HomeView(generic.ListView):
model = Category
template_name = 'home.html'
class ProductListView(generic.ListView):
template_name = 'product_list.html'
def get_queryset(self):
self.category = get_object_or_404(Category, title=self.kwargs['category'])
return Product.objects.filter(category=self.category)
class ProductDetailView(generic.DetailView):
model = Product
template_name = 'product_detail.html'
product_list.html
{% extends 'base.html' %}
{% load static %}
{% block title %}
Welcome | Global Market
{% endblock %}
{% block content %}
{% for product in product_list %}
<a href="{% url 'shop:product-detail' product.pk %}">
<div class="card bg-light mb-3" style="max-width: 18rem;">
<div class="card-header">{{ product.title }}</div>
<img class="card-img-top" src="{{ product.image.url }}" alt="{{ product.title }}">
<div class="card-body">
<p class="card-text">{{ product.description }}</p>
</div>
</div>
</a>
{% endfor %}
{% endblock %}
product_detail.html
{% extends 'base.html' %}
{% load static %}
{% block title %}
Welcome | Global Market
{% endblock %}
{% block content %}
<h1>thid</h1>
{{ product.name }}
{% endblock %}
Even if the you visit /categories/1, it will use the ProductListView, since the str path converter also accepts a sequence of digits. You can swap the paths, so:
from django.urls import path
from . import views
app_name = 'shop'
urlpatterns = [
path('', views.HomeView.as_view(), name='home'),
path('categories/<int:pk>/', views.ProductDetailView.as_view(), name='product-detail'),
path('categories/<category>/', views.ProductListView.as_view(), name='product-list'),
]
Then for /categories/1, it will match with <int:pk> as 1, and thus fire the ProductDetailView.

Signup page upon submission leads to error Django

I have built a site, where the user upon successful signup should be redirected to the login page. However it is not occurring so. Attached below are the relevant files:
Signup page html:
{% extends "base.html" %}
{% load bootstrap4 %}
{% block content %}
<div class="container">
<h1>Sign Up</h1>
<form method="POST" class="form">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">Sign Up</button>
{% endbuttons %}
</form>
</div>
{% endblock %}
Urls.py
from django.urls import path
from django.contrib.auth import views as auth_views
from . import views
app_name = 'accounts'
urlpatterns = [
path('login/', auth_views.LoginView.as_view(template_name="accounts/login.html"),name='login'),
path('logout/', auth_views.LogoutView.as_view(), name="logout"),
path('signup/', views.SignUp.as_view(), name="signup"),
]
views.py:
class SignUp(CreateView):
form_class = forms.UserCreateForm
success_url = reverse_lazy("login")
template_name = "accounts/signup.html"
Any help is appreciated. Thank you.

Django - Adding {% url %} in template with slug

I am trying to create the URL in order to access the EDIT and DELETE views directly from the post detail instead of typing it in the browser.
I am having trouble finding the right url pattern and template {% url %} code since there is a slug.
posts.urls
urlpatterns = [
url(r'^$', post_list, name='list'),
url(r'^create/$', post_create),
url(r'^(?P<slug>[\w-]+)/$', post_detail, name='detail'),
url(r'^(?P<slug>[\w-]+)/edit/$', post_update, name='update'),
url(r'^(?P<slug>[\w-]+)/delete/$', post_delete, name='delete'),
post_detail.html
{% block content %}
<div class='col-sm-6 col-sm-offset-3'>
{% if instance.image %}
<img src='{{ instance.image.url }}' class='img-responsive' />
{% endif %}
<h1>
{{ title }}
<small>
{% if instance.draft %}
<span style='color:red;'>Draft</span>
{% endif %}{{ instance.publish }}
<div class=''>
Edit |
Delete
</div>
</small>
</h1>
You need to pass the slug into the url tag in the html.
Try something like this,
Edit
Delete

NoReverseMatch at /; error at line 0

I'm getting the below error and I have no idea why... I swear everything was working fine yesterday... I'm using python 3.5 and django 1.9. I went through most of the NOReverseMatch posts, but I couldn't find anything... please help
"Reverse for 'xxx' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []"
and
In template F:\Django-tutorial\src\landing_pages\templates\landing_pages\home.html, error at line 0
home.html should be displayed as a main page
My projects url.py:
urlpatterns = [
url(r'^', include('landing_pages.urls')),
url(r'^admin/', admin.site.urls),
url(r'^in/', include('web_monitor.urls')),
]
landing_pages.urls:
from django.conf.urls import url
from landing_pages.views import home, contact, about, cost
urlpatterns = [
url(r'^$', home, name='home'),
url(r'^contact/$', contact, name='contact'),
url(r'^about/$', about, name='about'),
url(r'^cost/$', cost, name='cost'),
]
Home.html:
{% extends 'landing_pages/base.html' %}
{% load crispy_forms_tags %}
{% block jumbotron %}
<!-- Main component for a primary marketing message or call to action -->
<div class="jumbotron">
{% endblock %}
{% block content %}
<div class="row">
<div class="col-md-3">
<form method="POST" action="">
{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-primary" type="submit" value="Submit">
</form>
</div>
</div>
{% endblock %}
base.html:
{% load staticfiles %}
<html lang="en">
<head>
{% include 'landing_pages/head_css.html' %}
</head>
<body>
{% include 'landing_pages/nav_bar.html' %}
<div class="container">
{% block jumbotron %}
{% endblock %}
{% block content %}
{% endblock %}
</div> <!-- /container -->
</body>
</html>
nav_bar.html is just a nav bar, where i reference links like this:
<li>Cost</li>

Django Login App Tutorial problems

I am having problems running through a tutorial and it seems the problems stem from this:
(r'^l/login/$', 'django.contrib.auth.views.login'),
It seems I have done all correct, but the forms dont show.
If I hit Login. I get back to the same page without forms.
Did I miss something?
Here the code:
urls.py:
from django.conf.urls.defaults import *
from formsapp.views import *
from login.views import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
#Forms1:
(r'^$', main_page),
#Forms2
(r'^register/', main_page1),
#FormsLogin:
(r'^l/', login_main_page),
(r'^l/login/$', 'django.contrib.auth.views.login'),
(r'^l/logout/$', 'logout_page'),
views.py:
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.contrib.auth import logout
from django.contrib.auth.models import User
from django.template import RequestContext
from django.shortcuts import render_to_response
def login_main_page(request):
return render_to_response('mainpage.html', RequestContext(request))
def logout_page(request):
logout(request)
return HttpResponseRedirect('/l/')
base.html:
<html>
<head>
<title> {% block title %}{% endblock %}</title>
</head>
<body>
<h1>{% block head %}{% endblock %}</h1>
{% block content %}{% endblock %}
<br>
<br>
<br>
Login Main Page
{% if user.is_authenticated %}
Log out
{% else %}
Log in
{% endif %}
</body>
</html>
login.html:
{% extends "base.html" %}
{% block title %}Log in{% endblock %}
{% block head %}Log in{% endblock %}
{% block content %}
{% if form.has_errors %}
<p> Username or password didn't work. Please enter them again </p>
{% endif %}
<form method="post" action=".">
<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="/l/" />
<input type="submit" value="Log in" />
</form>
{% endblock %}
URL pattern
(r'^l/', login_main_page),
will match any URL starting with l/ and it is placed before l/login so second one won't be called, you should terminate regexp with $:
(r'^l/$', login_main_page),