Issue with passing parameters in urls

23 views
Skip to first unread message

aniket kamthe

unread,
Mar 30, 2020, 11:03:44 AM3/30/20
to Django users
Hey All, 
I have been watching your youtube tutorials and have been stuck on an issue for a while now. Can you help me out pls - 

I am trying to pass a parameter via a button in an HTML file and using that in the next link to access a specific set of entries from the database - 

HTML File code - 

{% for thread in object %}
<tr>
<td><a href="{% url 'message' thread.id %}" class="btn btn-primary" role="button">{{ thread.name }}</a></td>
<td>Something</td>
</tr>
{% endfor %}
URLs files code - 
path('message/<int:threadid>/', views.message, name='message'),
Views files code 
def message(request, threadid):
if request.method == 'POST':
print(request.POST.get('message'))
m = messages(message=request.POST.get('message'), thread_id='00', likes='00', Message_flags='00')
m.save();
if (request.method == 'POST') and ("like" in request.POST):
print("hi")
data = messages.objects.all()
context = {
'object': data
}
return render(request, 'mysite/message.html', context)
else:
data = messages.objects.all()
context = {
'object': data
}
return render(request, 'mysite/message.html', context)
But I get this error, idk how to resolve this one - 

image.png
Pls let me know If you are able to figure out the problem. 

Antje Kazimiers

unread,
Apr 1, 2020, 5:03:21 AM4/1/20
to django...@googlegroups.com

Hi Aniket,

Your thread object in your template is actually a message since your passing messages to context in your view.

but when you initialize messages you don't set a name attribute.

So I would double check your Message model if it has a name attribute.

btw your error message didn't display for me.

Antje

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/deae3154-4d36-438a-9669-5698d319ed27%40googlegroups.com.

aniket kamthe

unread,
Apr 1, 2020, 5:20:40 AM4/1/20
to django...@googlegroups.com
hey Antje, 
Let me check and get back. I think I have got the problem, I will get back if I have further issues. 



--
Aniket Kamthe
Final year Student | Dual Degree 
Department of Mechanical Engineering
Masters in Robotics 
Indian Institute Of Technology Madras.
Contact : +91-9970320507

Reply all
Reply to author
Forward
0 new messages