Reverse for 'post_detail' with arguments '()' and keyword arguments '{'pk': 1}' not found. 1 pattern(s) tried:

2,144 views
Skip to first unread message

sankar vasu

unread,
Sep 19, 2015, 7:59:31 AM9/19/15
to django...@googlegroups.com
Hi All,

I got below error, please advise. please look at the following link: http://pysan.pythonanywhere.com/

Inline image 1


url.py

from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^$', views.post_list, name='post_list'),
    url(r'^post/(?P<pk>[0-9]+)/$', views.post_detail, name='post_detail'),
]


view.py

from django.shortcuts import render, get_object_or_404
from django.utils import timezone
from .models import Post

def post_list(request):
    posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
    return render(request, 'blog/post_list.html', {'posts': posts})

def post_detail(request, pk):
    post = get_object_or_404(Post, pk=pk)
    return render(request, 'blog/post_detail.html', {'post': post})


Thanks in advance,
Sankar B

Luis Zárate

unread,
Sep 21, 2015, 11:03:25 PM9/21/15
to django...@googlegroups.com
The error is in the template, please check the url statement inside the template.

Or share with ours the template file.


El sábado, 19 de septiembre de 2015, sankar vasu <sanka...@gmail.com> escribió:
> Hi All,
>
> I got below error, please advise. please look at the following link: http://pysan.pythonanywhere.com/
>
> </mail/u/0/s/?view=att&th=14fe57938a35ee8f&attid=0.1&disp=emb&realattid=ii_14fe489d7752bc59&zw&atsh=1>

>
>
> url.py
>
> from django.conf.urls import url
> from . import views
>
> urlpatterns = [
>     url(r'^$', views.post_list, name='post_list'),
>     url(r'^post/(?P<pk>[0-9]+)/$', views.post_detail, name='post_detail'),
> ]
>
>
> view.py
>
> from django.shortcuts import render, get_object_or_404
> from django.utils import timezone
> from .models import Post
>
> def post_list(request):
>     posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
>     return render(request, 'blog/post_list.html', {'posts': posts})
>
> def post_detail(request, pk):
>     post = get_object_or_404(Post, pk=pk)
>     return render(request, 'blog/post_detail.html', {'post': post})
>
>
> Thanks in advance,
> Sankar B
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPzi0vCzoaSN%2B6xEL%3D%2BPSu_vQMpqG6i8oFw9y4_mtPvO8xtoeg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>

--
"La utopía sirve para caminar" Fernando Birri



Remco Gerlich

unread,
Sep 22, 2015, 4:06:59 AM9/22/15
to django...@googlegroups.com
According to the error, your pattern starts with $, which is an obvious mistake.

But the "url.py" you quote has ^.

Maybe it was using an old version, or you haven't copied the right one.

Greetings,
Remco Gerlich


--

sankar vasu

unread,
Sep 22, 2015, 2:50:12 PM9/22/15
to django...@googlegroups.com
Dear Luis,

FYI:

post_detail.html
-----------------------
{% extends "blog/base.html" %}

{% block content %}
    <div class="post">
        {% if post.published_date %}
            <div class="date">
                {{ post.published_date }}
            </div>
        {% endif %}
        <h1>{{ post.title }}</h1>
        <p>{{ post.text|linebreaks }}</p>
    </div>
{% endblock %}

post_list.html
--------------------
{% extends "blog/base.html" %}
{% block content %}
{% for post in posts %}
    <div class="post">
        <h1><a href="{% url "post_detail" pk=post.pk %}">{{ post.title }}</a></h1>
        <p align="justify">{{ post.text|linebreaks }}</p>
        <p align="right" class="date">Web published: {{ post.published_date }}</p>
    </div>
{% endfor %}
{% endblock content %}

Thanks in Advance,
Sankar B


For more options, visit https://groups.google.com/d/optout.



--
By,

Sankar

Luis Zárate

unread,
Sep 22, 2015, 3:00:09 PM9/22/15
to django...@googlegroups.com

2015-09-22 12:48 GMT-06:00 sankar vasu <sanka...@gmail.com>:
<h1><a href="{% url "post_detail" pk=post.pk %}">{{ post.title }}</a></h1>

try:

<h1><a href="{% url "post_detail" post.pk %}">{{ post.title }}</a></h1>

If not found then check your project url.py , do you have something like


urlpatterns = [
    url(r'^$', include('myapp.urls') ),
    ....
]

sankar vasu

unread,
Sep 23, 2015, 3:17:36 PM9/23/15
to django...@googlegroups.com
Dear Luis,

As you said, i tried but can't success.

Thanks in advance
Sankar B

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.



--
By,

Sankar

Luis Zárate

unread,
Sep 23, 2015, 3:36:07 PM9/23/15
to django...@googlegroups.com

As Remco said your problem are with your pattern because starts with $ or have  ^$



[projectname]/ ├── [projectname]/ │   ├── __init__.py │   ├── settings.py │   ├── urls.py <-- The error is here │   └── wsgi.py └── manage.py
└── blog/ └── __init__.py └── models.py └── managers.py └── views.py └── urls.py


In the urls.py do you have somethig like this ?

urlpatterns = patterns('',
url(r'^$', include('blog.urls')), <-- The error is here
url(r'^admin/', include(admin.site.urls)),
)


For more options, visit https://groups.google.com/d/optout.



--

sankar vasu

unread,
Sep 24, 2015, 2:49:04 PM9/24/15
to django...@googlegroups.com
Dear Luis, I got it. Thank you so much.



For more options, visit https://groups.google.com/d/optout.



--
By,

Sankar
Reply all
Reply to author
Forward
0 new messages