Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['blog/article//']





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I created a simple article/blog app. I am having problem in detail view. I created a list view of articles and also created a detail view if someone clicks on one of the acrticle , it takes the to detail view of article .



But when i click on one of the articles , i am getting above error stated in the title. It is also pointing the error location to
this code {% url "detail" post.id %} which u can see in 44th or 45th line in Error page i posted in the last.



I tried lots of thing , none worked.
I posted all my project files below. you can have look.
I would be glad if you guys helps me.



My code goes here :



Views.py



from django.shortcuts import render , redirect , get_object_or_404
from django.shortcuts import render , redirect , get_object_or_404
from .models import Article , members
from django.views.generic import ListView , DetailView
from .forms import create_form

class article_view(ListView):
model = Article
template_name = "article.html"
context_object_name = "articles"

def post_creator(request):
if request.method == "POST":
form = create_form(request.POST)
if form.is_valid():
form.save()

return redirect("/blog/home/")

else:
form = create_form()
return render(request , "post_create.html" , {"form":form})

def registration(request):
if request.method == "POST":
form = members(request.POST)
if form.is_valid():
form.save()

return redirect("/blog/home/")

else:
form = members()
return render(request , "register.html" , {"form":form})


class post_detail_view(DetailView):
model = Article
template_name = "detail.html"


urls.py



from django.conf.urls import url
from . import views
from django.contrib.auth.views import LoginView , LogoutView
urlpatterns = [

url("home/" , views.article_view.as_view() , name="blog-home"),
url("create/" , views.post_creator , name="new_post"),
url("register/" , views.registration , name="register"),
url("login/" , LoginView.as_view(template_name="login.html") , name="login"),
url("logout/" , LogoutView.as_view(template_name="logout.html") , name="logout"),

url("article/<int:pk>/" , views.post_detail_view.as_view() , name="detail"),

]


article.html (you can assume this as a base.html template)



{% load static %}
<!DOCTYPE html>

<html>

<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">



<title>Home</title>
</head>


<body style="background-image: url('{% static 'wooden.jpg' %}');">
{% if user.is_authenticated %}
<fieldset style="position: absolute;top: 20px;right: 0px;width: 100px;">
<button class="btn btn-outline-info"; onclick="location.href='{% url 'logout' %}'">Logout</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;left: 20px;width: 100px;">
<button class="btn btn-outline-info">{{ user.username }}</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;right: 120px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'new_post' %}'">Create Post</button>
</fieldset>
{% else %}
<fieldset style="position: absolute;top: 20px;right: 0px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'login' %}'">Login</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;right: 80px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'register' %}'">Signup</button>
</fieldset>
{% endif %}

{% for post in articles %}
<div>

<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">
<h1><a href="{% url 'detail' post.id %}">{{ post.title }}</a></h1>
<p>Click to see detail Post !</p>
<small>Published by {{ post.author }} on {{ post.date_pub }}</small></br></br>
</fieldset>
</div>

{% endfor %}

</body>
</html>


detail.html



{% load static %}
<!DOCTYPE html>

<html>

<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">



<title>Home</title>
</head>


<body style="background-image: url('{% static 'wooden.jpg' %}');">
{% if user.is_authenticated %}
<fieldset style="position: absolute;top: 20px;right: 0px;width: 100px;">
<button class="btn btn-outline-info"; onclick="location.href='{% url 'logout' %}'">Logout</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;left: 20px;width: 100px;">
<button class="btn btn-outline-info">{{ user.username }}</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;right: 120px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'new_post' %}'">Create Post</button>
</fieldset>
{% else %}
<fieldset style="position: absolute;top: 20px;right: 0px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'login' %}'">Login</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;right: 80px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'register' %}'">Signup</button>
</fieldset>
{% endif %}


<div>

<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">
<h1>{{ object.title }}</h1>


</fieldset>

<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">
<p>{{ object.content }}</p>


</fieldset>

<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">

<small>Published by {{ object.author }} on {{ object.date_pub }}</small></br></br>
</fieldset>


</div>



</body>
</html>


Error page



NoReverseMatch at /blog/home/
Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['blog/article/<int:pk>/']
Request Method:
GET
Request URL:
http://127.0.0.1:8000/blog/home/
Django Version:
2.1
Exception Type:
NoReverseMatch
Exception Value:
Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['blog/article/<int:pk>/']
Exception Location:
C:UsersnitinAppDataLocalProgramsPythonPython37-32libsite-packagesdjangourlsresolvers.py in _reverse_with_prefix, line 622
Python Executable:
C:UsersnitinAppDataLocalProgramsPythonPython37-32python.exe
Python Version:
3.7.0
Python Path:
['C:\Users\nitin\Desktop\my_project',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32\python37.zip',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32\DLLs',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32\lib',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32',
'C:\Users\nitin\AppData\Roaming\Python\Python37\site-packages',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32\lib\site-packages']
Server time:
Mon, 5 Nov 2018 07:32:43 +0000

Error during template rendering
In template C:UsersnitinDesktopmy_projectblogtemplatesarticle.html, error at line 44
Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['blog/article/<int:pk>/']
34
</fieldset>
35
<fieldset style="position: absolute;top: 20px;right: 80px;width: 100px;">
36
<button class="btn btn-outline-info" onclick="location.href='{% url 'register' %}'">Signup</button>
37
</fieldset>
38
{% endif %}
39

40
{% for post in articles %}
41
<div>
42

43
<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">
44
<h1><a href="{% url 'detail' post.id %}">{{ post.title }}</a></h1>
45
<p>Click to see detail Post !</p>
46
<small>Published by {{ post.author }} on {{ post.date_pub }}</small></br></br>
47
</fieldset>
48
</div>
49

50
{% endfor %}
51

52
</body>
53
</html>









share|improve this question























  • Try using path instead of url: path("article/<int:pk>/", ...).

    – ikkuh
    Nov 5 '18 at 8:17











  • Hey , thanks ! that worked ! You guys are awesome ! Thank u again !

    – Nitin Khandagale
    Nov 5 '18 at 17:42


















0















I created a simple article/blog app. I am having problem in detail view. I created a list view of articles and also created a detail view if someone clicks on one of the acrticle , it takes the to detail view of article .



But when i click on one of the articles , i am getting above error stated in the title. It is also pointing the error location to
this code {% url "detail" post.id %} which u can see in 44th or 45th line in Error page i posted in the last.



I tried lots of thing , none worked.
I posted all my project files below. you can have look.
I would be glad if you guys helps me.



My code goes here :



Views.py



from django.shortcuts import render , redirect , get_object_or_404
from django.shortcuts import render , redirect , get_object_or_404
from .models import Article , members
from django.views.generic import ListView , DetailView
from .forms import create_form

class article_view(ListView):
model = Article
template_name = "article.html"
context_object_name = "articles"

def post_creator(request):
if request.method == "POST":
form = create_form(request.POST)
if form.is_valid():
form.save()

return redirect("/blog/home/")

else:
form = create_form()
return render(request , "post_create.html" , {"form":form})

def registration(request):
if request.method == "POST":
form = members(request.POST)
if form.is_valid():
form.save()

return redirect("/blog/home/")

else:
form = members()
return render(request , "register.html" , {"form":form})


class post_detail_view(DetailView):
model = Article
template_name = "detail.html"


urls.py



from django.conf.urls import url
from . import views
from django.contrib.auth.views import LoginView , LogoutView
urlpatterns = [

url("home/" , views.article_view.as_view() , name="blog-home"),
url("create/" , views.post_creator , name="new_post"),
url("register/" , views.registration , name="register"),
url("login/" , LoginView.as_view(template_name="login.html") , name="login"),
url("logout/" , LogoutView.as_view(template_name="logout.html") , name="logout"),

url("article/<int:pk>/" , views.post_detail_view.as_view() , name="detail"),

]


article.html (you can assume this as a base.html template)



{% load static %}
<!DOCTYPE html>

<html>

<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">



<title>Home</title>
</head>


<body style="background-image: url('{% static 'wooden.jpg' %}');">
{% if user.is_authenticated %}
<fieldset style="position: absolute;top: 20px;right: 0px;width: 100px;">
<button class="btn btn-outline-info"; onclick="location.href='{% url 'logout' %}'">Logout</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;left: 20px;width: 100px;">
<button class="btn btn-outline-info">{{ user.username }}</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;right: 120px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'new_post' %}'">Create Post</button>
</fieldset>
{% else %}
<fieldset style="position: absolute;top: 20px;right: 0px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'login' %}'">Login</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;right: 80px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'register' %}'">Signup</button>
</fieldset>
{% endif %}

{% for post in articles %}
<div>

<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">
<h1><a href="{% url 'detail' post.id %}">{{ post.title }}</a></h1>
<p>Click to see detail Post !</p>
<small>Published by {{ post.author }} on {{ post.date_pub }}</small></br></br>
</fieldset>
</div>

{% endfor %}

</body>
</html>


detail.html



{% load static %}
<!DOCTYPE html>

<html>

<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">



<title>Home</title>
</head>


<body style="background-image: url('{% static 'wooden.jpg' %}');">
{% if user.is_authenticated %}
<fieldset style="position: absolute;top: 20px;right: 0px;width: 100px;">
<button class="btn btn-outline-info"; onclick="location.href='{% url 'logout' %}'">Logout</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;left: 20px;width: 100px;">
<button class="btn btn-outline-info">{{ user.username }}</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;right: 120px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'new_post' %}'">Create Post</button>
</fieldset>
{% else %}
<fieldset style="position: absolute;top: 20px;right: 0px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'login' %}'">Login</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;right: 80px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'register' %}'">Signup</button>
</fieldset>
{% endif %}


<div>

<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">
<h1>{{ object.title }}</h1>


</fieldset>

<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">
<p>{{ object.content }}</p>


</fieldset>

<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">

<small>Published by {{ object.author }} on {{ object.date_pub }}</small></br></br>
</fieldset>


</div>



</body>
</html>


Error page



NoReverseMatch at /blog/home/
Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['blog/article/<int:pk>/']
Request Method:
GET
Request URL:
http://127.0.0.1:8000/blog/home/
Django Version:
2.1
Exception Type:
NoReverseMatch
Exception Value:
Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['blog/article/<int:pk>/']
Exception Location:
C:UsersnitinAppDataLocalProgramsPythonPython37-32libsite-packagesdjangourlsresolvers.py in _reverse_with_prefix, line 622
Python Executable:
C:UsersnitinAppDataLocalProgramsPythonPython37-32python.exe
Python Version:
3.7.0
Python Path:
['C:\Users\nitin\Desktop\my_project',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32\python37.zip',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32\DLLs',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32\lib',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32',
'C:\Users\nitin\AppData\Roaming\Python\Python37\site-packages',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32\lib\site-packages']
Server time:
Mon, 5 Nov 2018 07:32:43 +0000

Error during template rendering
In template C:UsersnitinDesktopmy_projectblogtemplatesarticle.html, error at line 44
Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['blog/article/<int:pk>/']
34
</fieldset>
35
<fieldset style="position: absolute;top: 20px;right: 80px;width: 100px;">
36
<button class="btn btn-outline-info" onclick="location.href='{% url 'register' %}'">Signup</button>
37
</fieldset>
38
{% endif %}
39

40
{% for post in articles %}
41
<div>
42

43
<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">
44
<h1><a href="{% url 'detail' post.id %}">{{ post.title }}</a></h1>
45
<p>Click to see detail Post !</p>
46
<small>Published by {{ post.author }} on {{ post.date_pub }}</small></br></br>
47
</fieldset>
48
</div>
49

50
{% endfor %}
51

52
</body>
53
</html>









share|improve this question























  • Try using path instead of url: path("article/<int:pk>/", ...).

    – ikkuh
    Nov 5 '18 at 8:17











  • Hey , thanks ! that worked ! You guys are awesome ! Thank u again !

    – Nitin Khandagale
    Nov 5 '18 at 17:42














0












0








0








I created a simple article/blog app. I am having problem in detail view. I created a list view of articles and also created a detail view if someone clicks on one of the acrticle , it takes the to detail view of article .



But when i click on one of the articles , i am getting above error stated in the title. It is also pointing the error location to
this code {% url "detail" post.id %} which u can see in 44th or 45th line in Error page i posted in the last.



I tried lots of thing , none worked.
I posted all my project files below. you can have look.
I would be glad if you guys helps me.



My code goes here :



Views.py



from django.shortcuts import render , redirect , get_object_or_404
from django.shortcuts import render , redirect , get_object_or_404
from .models import Article , members
from django.views.generic import ListView , DetailView
from .forms import create_form

class article_view(ListView):
model = Article
template_name = "article.html"
context_object_name = "articles"

def post_creator(request):
if request.method == "POST":
form = create_form(request.POST)
if form.is_valid():
form.save()

return redirect("/blog/home/")

else:
form = create_form()
return render(request , "post_create.html" , {"form":form})

def registration(request):
if request.method == "POST":
form = members(request.POST)
if form.is_valid():
form.save()

return redirect("/blog/home/")

else:
form = members()
return render(request , "register.html" , {"form":form})


class post_detail_view(DetailView):
model = Article
template_name = "detail.html"


urls.py



from django.conf.urls import url
from . import views
from django.contrib.auth.views import LoginView , LogoutView
urlpatterns = [

url("home/" , views.article_view.as_view() , name="blog-home"),
url("create/" , views.post_creator , name="new_post"),
url("register/" , views.registration , name="register"),
url("login/" , LoginView.as_view(template_name="login.html") , name="login"),
url("logout/" , LogoutView.as_view(template_name="logout.html") , name="logout"),

url("article/<int:pk>/" , views.post_detail_view.as_view() , name="detail"),

]


article.html (you can assume this as a base.html template)



{% load static %}
<!DOCTYPE html>

<html>

<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">



<title>Home</title>
</head>


<body style="background-image: url('{% static 'wooden.jpg' %}');">
{% if user.is_authenticated %}
<fieldset style="position: absolute;top: 20px;right: 0px;width: 100px;">
<button class="btn btn-outline-info"; onclick="location.href='{% url 'logout' %}'">Logout</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;left: 20px;width: 100px;">
<button class="btn btn-outline-info">{{ user.username }}</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;right: 120px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'new_post' %}'">Create Post</button>
</fieldset>
{% else %}
<fieldset style="position: absolute;top: 20px;right: 0px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'login' %}'">Login</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;right: 80px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'register' %}'">Signup</button>
</fieldset>
{% endif %}

{% for post in articles %}
<div>

<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">
<h1><a href="{% url 'detail' post.id %}">{{ post.title }}</a></h1>
<p>Click to see detail Post !</p>
<small>Published by {{ post.author }} on {{ post.date_pub }}</small></br></br>
</fieldset>
</div>

{% endfor %}

</body>
</html>


detail.html



{% load static %}
<!DOCTYPE html>

<html>

<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">



<title>Home</title>
</head>


<body style="background-image: url('{% static 'wooden.jpg' %}');">
{% if user.is_authenticated %}
<fieldset style="position: absolute;top: 20px;right: 0px;width: 100px;">
<button class="btn btn-outline-info"; onclick="location.href='{% url 'logout' %}'">Logout</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;left: 20px;width: 100px;">
<button class="btn btn-outline-info">{{ user.username }}</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;right: 120px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'new_post' %}'">Create Post</button>
</fieldset>
{% else %}
<fieldset style="position: absolute;top: 20px;right: 0px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'login' %}'">Login</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;right: 80px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'register' %}'">Signup</button>
</fieldset>
{% endif %}


<div>

<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">
<h1>{{ object.title }}</h1>


</fieldset>

<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">
<p>{{ object.content }}</p>


</fieldset>

<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">

<small>Published by {{ object.author }} on {{ object.date_pub }}</small></br></br>
</fieldset>


</div>



</body>
</html>


Error page



NoReverseMatch at /blog/home/
Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['blog/article/<int:pk>/']
Request Method:
GET
Request URL:
http://127.0.0.1:8000/blog/home/
Django Version:
2.1
Exception Type:
NoReverseMatch
Exception Value:
Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['blog/article/<int:pk>/']
Exception Location:
C:UsersnitinAppDataLocalProgramsPythonPython37-32libsite-packagesdjangourlsresolvers.py in _reverse_with_prefix, line 622
Python Executable:
C:UsersnitinAppDataLocalProgramsPythonPython37-32python.exe
Python Version:
3.7.0
Python Path:
['C:\Users\nitin\Desktop\my_project',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32\python37.zip',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32\DLLs',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32\lib',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32',
'C:\Users\nitin\AppData\Roaming\Python\Python37\site-packages',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32\lib\site-packages']
Server time:
Mon, 5 Nov 2018 07:32:43 +0000

Error during template rendering
In template C:UsersnitinDesktopmy_projectblogtemplatesarticle.html, error at line 44
Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['blog/article/<int:pk>/']
34
</fieldset>
35
<fieldset style="position: absolute;top: 20px;right: 80px;width: 100px;">
36
<button class="btn btn-outline-info" onclick="location.href='{% url 'register' %}'">Signup</button>
37
</fieldset>
38
{% endif %}
39

40
{% for post in articles %}
41
<div>
42

43
<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">
44
<h1><a href="{% url 'detail' post.id %}">{{ post.title }}</a></h1>
45
<p>Click to see detail Post !</p>
46
<small>Published by {{ post.author }} on {{ post.date_pub }}</small></br></br>
47
</fieldset>
48
</div>
49

50
{% endfor %}
51

52
</body>
53
</html>









share|improve this question














I created a simple article/blog app. I am having problem in detail view. I created a list view of articles and also created a detail view if someone clicks on one of the acrticle , it takes the to detail view of article .



But when i click on one of the articles , i am getting above error stated in the title. It is also pointing the error location to
this code {% url "detail" post.id %} which u can see in 44th or 45th line in Error page i posted in the last.



I tried lots of thing , none worked.
I posted all my project files below. you can have look.
I would be glad if you guys helps me.



My code goes here :



Views.py



from django.shortcuts import render , redirect , get_object_or_404
from django.shortcuts import render , redirect , get_object_or_404
from .models import Article , members
from django.views.generic import ListView , DetailView
from .forms import create_form

class article_view(ListView):
model = Article
template_name = "article.html"
context_object_name = "articles"

def post_creator(request):
if request.method == "POST":
form = create_form(request.POST)
if form.is_valid():
form.save()

return redirect("/blog/home/")

else:
form = create_form()
return render(request , "post_create.html" , {"form":form})

def registration(request):
if request.method == "POST":
form = members(request.POST)
if form.is_valid():
form.save()

return redirect("/blog/home/")

else:
form = members()
return render(request , "register.html" , {"form":form})


class post_detail_view(DetailView):
model = Article
template_name = "detail.html"


urls.py



from django.conf.urls import url
from . import views
from django.contrib.auth.views import LoginView , LogoutView
urlpatterns = [

url("home/" , views.article_view.as_view() , name="blog-home"),
url("create/" , views.post_creator , name="new_post"),
url("register/" , views.registration , name="register"),
url("login/" , LoginView.as_view(template_name="login.html") , name="login"),
url("logout/" , LogoutView.as_view(template_name="logout.html") , name="logout"),

url("article/<int:pk>/" , views.post_detail_view.as_view() , name="detail"),

]


article.html (you can assume this as a base.html template)



{% load static %}
<!DOCTYPE html>

<html>

<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">



<title>Home</title>
</head>


<body style="background-image: url('{% static 'wooden.jpg' %}');">
{% if user.is_authenticated %}
<fieldset style="position: absolute;top: 20px;right: 0px;width: 100px;">
<button class="btn btn-outline-info"; onclick="location.href='{% url 'logout' %}'">Logout</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;left: 20px;width: 100px;">
<button class="btn btn-outline-info">{{ user.username }}</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;right: 120px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'new_post' %}'">Create Post</button>
</fieldset>
{% else %}
<fieldset style="position: absolute;top: 20px;right: 0px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'login' %}'">Login</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;right: 80px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'register' %}'">Signup</button>
</fieldset>
{% endif %}

{% for post in articles %}
<div>

<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">
<h1><a href="{% url 'detail' post.id %}">{{ post.title }}</a></h1>
<p>Click to see detail Post !</p>
<small>Published by {{ post.author }} on {{ post.date_pub }}</small></br></br>
</fieldset>
</div>

{% endfor %}

</body>
</html>


detail.html



{% load static %}
<!DOCTYPE html>

<html>

<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">



<title>Home</title>
</head>


<body style="background-image: url('{% static 'wooden.jpg' %}');">
{% if user.is_authenticated %}
<fieldset style="position: absolute;top: 20px;right: 0px;width: 100px;">
<button class="btn btn-outline-info"; onclick="location.href='{% url 'logout' %}'">Logout</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;left: 20px;width: 100px;">
<button class="btn btn-outline-info">{{ user.username }}</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;right: 120px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'new_post' %}'">Create Post</button>
</fieldset>
{% else %}
<fieldset style="position: absolute;top: 20px;right: 0px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'login' %}'">Login</button>
</fieldset>
<fieldset style="position: absolute;top: 20px;right: 80px;width: 100px;">
<button class="btn btn-outline-info" onclick="location.href='{% url 'register' %}'">Signup</button>
</fieldset>
{% endif %}


<div>

<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">
<h1>{{ object.title }}</h1>


</fieldset>

<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">
<p>{{ object.content }}</p>


</fieldset>

<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">

<small>Published by {{ object.author }} on {{ object.date_pub }}</small></br></br>
</fieldset>


</div>



</body>
</html>


Error page



NoReverseMatch at /blog/home/
Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['blog/article/<int:pk>/']
Request Method:
GET
Request URL:
http://127.0.0.1:8000/blog/home/
Django Version:
2.1
Exception Type:
NoReverseMatch
Exception Value:
Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['blog/article/<int:pk>/']
Exception Location:
C:UsersnitinAppDataLocalProgramsPythonPython37-32libsite-packagesdjangourlsresolvers.py in _reverse_with_prefix, line 622
Python Executable:
C:UsersnitinAppDataLocalProgramsPythonPython37-32python.exe
Python Version:
3.7.0
Python Path:
['C:\Users\nitin\Desktop\my_project',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32\python37.zip',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32\DLLs',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32\lib',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32',
'C:\Users\nitin\AppData\Roaming\Python\Python37\site-packages',
'C:\Users\nitin\AppData\Local\Programs\Python\Python37-32\lib\site-packages']
Server time:
Mon, 5 Nov 2018 07:32:43 +0000

Error during template rendering
In template C:UsersnitinDesktopmy_projectblogtemplatesarticle.html, error at line 44
Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['blog/article/<int:pk>/']
34
</fieldset>
35
<fieldset style="position: absolute;top: 20px;right: 80px;width: 100px;">
36
<button class="btn btn-outline-info" onclick="location.href='{% url 'register' %}'">Signup</button>
37
</fieldset>
38
{% endif %}
39

40
{% for post in articles %}
41
<div>
42

43
<fieldset style="width:45%;padding: 15px ;background-color: white;margin-left: 150px;margin-bottom: 10px;margin-top: 20px;border: 3px solid #20B2AA;opacity: 0.7; ">
44
<h1><a href="{% url 'detail' post.id %}">{{ post.title }}</a></h1>
45
<p>Click to see detail Post !</p>
46
<small>Published by {{ post.author }} on {{ post.date_pub }}</small></br></br>
47
</fieldset>
48
</div>
49

50
{% endfor %}
51

52
</body>
53
</html>






django django-views detailsview






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 5 '18 at 8:13









Nitin KhandagaleNitin Khandagale

166




166













  • Try using path instead of url: path("article/<int:pk>/", ...).

    – ikkuh
    Nov 5 '18 at 8:17











  • Hey , thanks ! that worked ! You guys are awesome ! Thank u again !

    – Nitin Khandagale
    Nov 5 '18 at 17:42



















  • Try using path instead of url: path("article/<int:pk>/", ...).

    – ikkuh
    Nov 5 '18 at 8:17











  • Hey , thanks ! that worked ! You guys are awesome ! Thank u again !

    – Nitin Khandagale
    Nov 5 '18 at 17:42

















Try using path instead of url: path("article/<int:pk>/", ...).

– ikkuh
Nov 5 '18 at 8:17





Try using path instead of url: path("article/<int:pk>/", ...).

– ikkuh
Nov 5 '18 at 8:17













Hey , thanks ! that worked ! You guys are awesome ! Thank u again !

– Nitin Khandagale
Nov 5 '18 at 17:42





Hey , thanks ! that worked ! You guys are awesome ! Thank u again !

– Nitin Khandagale
Nov 5 '18 at 17:42












1 Answer
1






active

oldest

votes


















0














You're confusing the URL syntaxes. url() takes a regex; for the new-style format you need to use path().



path("article/<int:pk>/" , views.post_detail_view.as_view() , name="detail"),





share|improve this answer
























  • Oh my god , that worked ! You are like angel. Its been 2 days i am struggeling to solve this but couldnt. Awesome dude , just awesome ! keep shining .

    – Nitin Khandagale
    Nov 5 '18 at 17:41












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53150539%2freverse-for-detail-with-arguments-1-not-found-1-patterns-tried-blog%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You're confusing the URL syntaxes. url() takes a regex; for the new-style format you need to use path().



path("article/<int:pk>/" , views.post_detail_view.as_view() , name="detail"),





share|improve this answer
























  • Oh my god , that worked ! You are like angel. Its been 2 days i am struggeling to solve this but couldnt. Awesome dude , just awesome ! keep shining .

    – Nitin Khandagale
    Nov 5 '18 at 17:41
















0














You're confusing the URL syntaxes. url() takes a regex; for the new-style format you need to use path().



path("article/<int:pk>/" , views.post_detail_view.as_view() , name="detail"),





share|improve this answer
























  • Oh my god , that worked ! You are like angel. Its been 2 days i am struggeling to solve this but couldnt. Awesome dude , just awesome ! keep shining .

    – Nitin Khandagale
    Nov 5 '18 at 17:41














0












0








0







You're confusing the URL syntaxes. url() takes a regex; for the new-style format you need to use path().



path("article/<int:pk>/" , views.post_detail_view.as_view() , name="detail"),





share|improve this answer













You're confusing the URL syntaxes. url() takes a regex; for the new-style format you need to use path().



path("article/<int:pk>/" , views.post_detail_view.as_view() , name="detail"),






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 5 '18 at 8:37









Daniel RosemanDaniel Roseman

461k42597655




461k42597655













  • Oh my god , that worked ! You are like angel. Its been 2 days i am struggeling to solve this but couldnt. Awesome dude , just awesome ! keep shining .

    – Nitin Khandagale
    Nov 5 '18 at 17:41



















  • Oh my god , that worked ! You are like angel. Its been 2 days i am struggeling to solve this but couldnt. Awesome dude , just awesome ! keep shining .

    – Nitin Khandagale
    Nov 5 '18 at 17:41

















Oh my god , that worked ! You are like angel. Its been 2 days i am struggeling to solve this but couldnt. Awesome dude , just awesome ! keep shining .

– Nitin Khandagale
Nov 5 '18 at 17:41





Oh my god , that worked ! You are like angel. Its been 2 days i am struggeling to solve this but couldnt. Awesome dude , just awesome ! keep shining .

– Nitin Khandagale
Nov 5 '18 at 17:41




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53150539%2freverse-for-detail-with-arguments-1-not-found-1-patterns-tried-blog%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)