user5504795 user5504795 - 1 year ago 73
Python Question

Reverse for '' with arguments '()' and keyword arguments not found. Django

I have been having trouble with this for a few dayss and havent been able to find any answers. Basically I want the url to be the / as in if its print then I want /print.

I understand that my regex is probably wrong and will need changed, but here is my code.


url(r'^(?P<pk>)/$', views.page_detail, name='page_detail'),

It throws the error on line 5

{% extends 'wiki/base.html' %}

{% block content %}
{% for page in pages %}
<h1><a href="{% url 'page_detail' %}">{{ page.function }}</a></h1>
<p>{{ page.usage|linebreaksbr }}</p>
{% endfor %}
{% endblock %}

def page_detail(request, pk):
page = get_object_or_404(Page, pk=pk)
return render(request, 'wiki/page_detail.html', {'page': page})


{% extends 'wiki/base.html' %}

{% block content %}
<h1>{{ page.function }}</h1>
<p>{{ page.usage|linebreaksbr }}</p>

{% endblock %}

The specific error is

Reverse for 'page_detail' with arguments '()' and keyword arguments '{'pk': 'print'}' not found. 1 pattern(s) tried: ['page/(?P<pk>)/$']

if anyone has any ideas or resources for me to look at I would appreciate it.

edit: include page model

class Page(models.Model):
function = models.CharField(max_length=100, primary_key=True)
usage = models.CharField(max_length=200)
author = models.CharField(max_length=100)
library = models.CharField(max_length=100)
parameters = models.TextField()
returnValues = models.CharField(max_length=100)
examples = models.TextField()
notes = models.TextField()
seeAlso = models.TextField()

Answer Source

From your question, it seems you have more than one url that points to that view. So, remove the duplicate url. If that's not the issue then make sure you are passing the "object id" correctly through the url. The "object id" (?P<pk>\d+) is a required parameter in the url to DetailView.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download