Monday, March 30, 2020

Issue with passing parameters in urls

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. 

--
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+unsubscribe@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.

No comments:

Post a Comment