Wednesday, April 1, 2020

Re: Issue with passing parameters in urls

hey Antje, 
Let me check and get back. I think I have got the problem, I will get back if I have further issues. 

On Wed, Apr 1, 2020 at 2:32 PM Antje Kazimiers <ntjkazim@gmail.com> wrote:

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

On 3/30/20 4:50 PM, aniket kamthe wrote:
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.

--
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/879b4154-a801-9080-96a3-0f28e5e38ac1%40gmail.com.


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

--
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/CAKFu1CFy9eZhm1oCk3YC8yof220t__J%2BtEx%2B9Yjnto%3Dk8hMOtQ%40mail.gmail.com.

No comments:

Post a Comment