'str' object has no attribute 'objects'

883 views
Skip to first unread message

Chetan Rokade

unread,
Dec 28, 2019, 6:00:53 AM12/28/19
to Django users
Hi Friends,
Getting below error while doing search operation :
'str' object has no attribute 'objects'

Code:
1) html having search button :
<form method="POST" action="SearchCR">
        {% csrf_token %}
        <div class="form-group">
            <div class="col-lg-5">
                <input type="text" name="CR_NAME" class="form-control" placeholder="Enter Application">
            </div>
            <label class="col-lg-2">
                <button type="submit" class="btn btn-primary"> Search </button>
            </label>
        </div>
    </form>


Chetan Rokade

unread,
Dec 28, 2019, 6:02:48 AM12/28/19
to Django users
2) views.py :
def SearchCR(request):
    if request.method == "POST":
        CR = request.POST['CR_NAME']

        if CR:
            match = CR.objects.filter(Q(App_Name__icontains=CR) |
                                      Q(CR_Status__icontains=CR)
                                      )
            if match:
                return render(request, 'changes/changes.html', {'CR': match})
            else:
                messages.error(request, 'No result found')

        else:
            return redirect('changes')

    return render(request, 'changes/changes.html')

gaurav jain

unread,
Dec 28, 2019, 6:11:31 AM12/28/19
to django...@googlegroups.com
Show the backend code of the post request 
Regards
Gaurav Jain

--
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/80817360-1f88-4980-a628-89f6ee24b1d3%40googlegroups.com.

Suraj Thapa FC

unread,
Dec 28, 2019, 6:19:47 AM12/28/19
to django...@googlegroups.com
Cr is string not a model that's why this error is coming...
change the name of cr variable in which you are taking the request data 

Chetan Rokade

unread,
Dec 28, 2019, 6:33:53 AM12/28/19
to Django users
This is resolved now. I had used variable name same as class name. 

Regards,
Chetan


On Saturday, December 28, 2019 at 4:30:53 PM UTC+5:30, Chetan Rokade wrote:

Chetan Rokade

unread,
Dec 28, 2019, 6:44:14 AM12/28/19
to django...@googlegroups.com
Thanks Suraj Thapa. 


Sent from Yahoo Mail for iPhone
Chetan
                <button type=" submit" class="btn btn- primary"> Search </button>
            </label>
        </div>
    </form>


--
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
Reply all
Reply to author
Forward
0 new messages