Reverse for 'edit' with arguments '(9,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []
<p>I'm getting an error when trying to access edit link in django, i have looked here on stack overflow but i haven't found the solution that works in my case.</p>

<p>ERROR : 
Exception Type : NoReverseMatch 
Exception Value : Reverse for 'edit' with arguments '(9,)' and keyword arguments '{}' not found. 0 pattern(s) tried: [] arguments '{}' not found. 0 pattern(s) tried: []</p>

<p>this is my urls.py</p>

<pre><code>from django.conf.urls import url, include
from django.contrib import admin
from posts import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^create/$', views.create, name='create'),
    url(r'^(?P&lt;id&gt;\d+)/$', views.show_post, name = 'show_post'),
    url(r'^(?P&lt;id&gt;\d+)/edit/$', views.update_post, name = 'update_post'),
    url(r'^(?P&lt;id&gt;\d+)/delete/$', views.delete_post),
]
</code></pre>

<p>views.py</p>

<pre class="lang-py prettyprint-override"><code>from django.contrib import messages
from django.shortcuts import render, get_object_or_404, redirect
from django.http import HttpResponse, HttpResponseRedirect

from .forms import PostForm
from .models import Post

# Create your views here.

def index(request):
    post_list = Post.objects.order_by('-created_date')[:10]
    context = {'post_list': post_list}
    return render(request, 'index.html', context)

def create(request):
    form = PostForm(request.POST or None)
    if form.is_valid():
        instance = form.save(commit=False)
        instance.save()
        #flass messages
        messages.success(request, "Successfully created")
        return HttpResponseRedirect(instance.get_absolute_url())


    context = {
        "form":form,
    }
    return render(request, 'post_form.html', context)   


def show_post(request, id=None):
    instance = get_object_or_404(Post, id=id)
    context = {'instance': instance}
    return render(request, 'show_post.html', context)


def update_post(request, id=None):
    instance = get_object_or_404(Post, id=id)
    form = PostForm(request.POST or None, instance=instance)
    if form.is_valid():
        instance = form.save(commit=False)
        instance.save()
        messages.success(request, "Post updated")
        return HttpResponseRedirect(instance.get_absolute_url())
    context = {
        "form":form,
        "instance":instance
    }
    return render(request, 'post_form.html', context)


def delete_post(request, id=None):
    instance = get_object_or_404(Post, id=id)
    instance.delete()
    messages.success(request, "Successfully deleted")
    return redirect("posts:index")
</code></pre>

<p>show_post.html</p>

<pre><code>{% extends "base.html" %}

&lt;div class="container"&gt;
{% block content  %}
    &lt;h1&gt; {{instance.title}} &lt;/h1&gt;
    &lt;h3&gt;{{instance.content| linebreaks}} &lt;/h3&gt;
    &lt;a href="{% url 'posts:index' %}"&gt; Home&lt;/a&gt; | &lt;a href="{{instance.url}}" target="_blank" &gt; visit url&lt;/a&gt; | 
    &lt;a href="{% url 'posts:update_post' %}"&gt; Edit&lt;/a&gt; 

{% endblock %}

&lt;/div&gt;
</code></pre>

<p>You need to use the namespace. Rather than <code>'edit'</code>, you should use <code>'posts:edit'</code>.</p>

<p>Or <code>'posts:update_post'</code> depending which name you're using in urls.py.</p>

python django django-models django-templates django-views