Django error no reverse match with arguments '('',)'


I feel kinda bad using my first post as a cry for help but hey, im certainly not the first lulz, anyway, im teaching myself python/django and im really stuck atm and ive been slogging through problems myself lately and wasting a lot of time doing it and this one has me stuck.

Im getting the error: NoReverseMatch at /messages/newreply/1/
Reverse for ‘newreply’ with arguments ‘(”,)’ not found. 1 pattern(s) tried: [‘messages/newreply/(?P<post_id>[0-9]+)/\Z’]

This is my url file;

app_name = 'board'
urlpatterns = [
    path('', views.index, name='index'),
    path('<int:post_id>/', views.postdetail, name='detail'),
    path('newmsg/', views.newmsg, name='newmsg'),
    path('newreply/<int:post_id>/', views.newreply, name='newreply')


def newreply(request, post_id):
    post = Post.objects.get(id=post_id)
    if request.method != "POST":
        form = ReplyForm()
        form = ReplyForm(data=request.POST)
        if form.is_valid():
   = post
            return redirect('board:index')
    context = {'form':form}
    return render(request, 'board/newreply.html', context)


{% extends 'pages/base.html' %}
{% block content %}

<p>Add your reply here</p>
<form action="{% url 'board:newreply' %}"method ='post'>
    {% csrf_token %}
    {{ form.as_p }}
    <button name = "submit">Add post</button>
{% endblock content %}

Ive tried so many things now im not even sure where i began anymore so id really appreciate any help, especially knowing why its actually happening as ive read through a few posts with the same type of error but trying the solutions posted has produced other errors for me.

Thank you!


It is indeed a useless and annoying error. Usually, it means you haven’t passed something in the context of the request. In this case, the post object.

context = {'form':form, 'post': post}
return render(request, 'board/newreply.html', context)

Answered By – vinkomlacic

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published