Reputation: 1963
I have form that has been generated by django and i'm trying to return an object id with the form to the function.
I received this error .I can't seem to figure out why it doesn't work cause picture id is valid id and the regex of the URL should capture it and return it to my functions unless the current URL must match because my current URL for the page is is 1:8000/comment/1/
Reverse for 'world.CommentCreator' with arguments '(1,)' and keyword arguments '{}' not found.
File "C:\o\17\mysite\pet\views.py" in CommentCreator
269. return render(request,'commentcreator.html', {'comment':comment,'picture':p,'search':CommentsForm()})
My views.py
def CommentCreator(request,picture_id):
p = Picture.objects.get(pk=picture_id)
comment = Comment.objects.filter(picture=p)
return render(request,'commentcreator.html', {'comment':comment,'picture':p,'search':CommentsForm()})
My URL.py
url(
r'^comment/(?P<picture_id>\d+)/$',
'pet.views.CommentCreator',
name = 'CommentCreator',
),
Html
{% if picture.image %}
{% endif %}
<ul>
<br><img src="{{ picture.image.url }}">
</ul>
{% for c in comment %}
{% ifequal c.picture.id picture.id %}
<br>{{ c.body }}</li>
<br>{{ c.created}}</li>
<br>{{ c.user}}</li>
{% endifequal %}
{% endfor %}
<br><br><br><br>
{% if picture %}
<form method = "post" action"{% url world.CommentCreator picture.id %}">{% csrf_token %}
{{search}}
<input type ="submit" value="Search "/>
</form>
{% endif %}
Upvotes: 0
Views: 3093
Reputation: 22808
You put .
instead of :
in the url
<form method = "post" action"{% url world.CommentCreator picture.id %}">
{% csrf_token %}
It must be
<form method = "post" action"{% url world:CommentCreator picture.id %}">
{% csrf_token %}
Upvotes: 0
Reputation: 39699
You need to use the url name in url tag:
{% url CommentCreator picture.id %}
That's it, single quote around url name is not necessary if you are on django < 1.3. It still work in django 1.4 but it is deprecated and it is completely remove in django 1.5.
For future compatibility you should use this method if on django < 1.5:
{% load url from future %}
{% url 'CommentCreator' picture.id %}
For the named capturing group URL's it is not necessary to pass URL params as keywords or args, both will work (but it is important to know the order, that is why keywords params are more preferable in URL tag):
{% load url from future %}
{% url 'CommentCreator' picture.id %}
{% url 'CommentCreator' picture_id=picture.id %}
Upvotes: 3
Reputation: 8198
Your URL configuration uses keyword arguments for the CommentCreator view, supply them to url
as such:
{% url 'CommentCreator' picture_id=picture.id %}
Upvotes: 0