Reputation: 2031
I try delete object in my app. I get error:
Reverse for 'delete' with arguments '()' and keyword arguments '{u'pk': 4}' not found. 1 pattern(s) tried: [u'$delete/(?P\d+)/$']
Below is my code - model, view, url.
In template I have this code:
<li>{{ user.name }} | <a href="{% url 'app:delete' pk=user.id %}">Delete</a></li>
My standard model with random function:
from django.db import models
import random
def random_id():
r = random.randint(0, 100)
return r
class User(models.Model):
rand_id = models.IntegerField(default=random_id)
name = models.CharField(max_length=255)
birthday = models.DateField()
def __unicode__(self):
return self.name
My view:
class Delete(generic.DeleteView):
""" """
model = User
template_name = 'App/confirm.html'
def get_success_url(self):
return reverse('app:index'
)
My url in app:
from django.conf.urls import patterns, url
import views
urlpatterns = patterns('',
url(r'^$', views.Index.as_view(), name="index"),
url(r'^delete/(?P<pk>\d+)/$', views.Delete.as_view(), name='delete'),
)
My url in project:
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'^$', include('App.urls', namespace="app")),
url(r'^admin/', include(admin.site.urls))
Upvotes: 0
Views: 434
Reputation: 599600
Don't terminate the regex with a $ when you're including another urlconf.
url(r'', include('App.urls', namespace="app")),
Upvotes: 2