'str' object has no attribute 'objects'

瀏覽次數:886 次
跳到第一則未讀訊息

Chetan Rokade

未讀,
2019年12月28日 清晨6:00:532019/12/28
收件者: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

未讀,
2019年12月28日 清晨6:02:482019/12/28
收件者: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

未讀,
2019年12月28日 清晨6:11:312019/12/28
收件者: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

未讀,
2019年12月28日 清晨6:19:472019/12/28
收件者: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

未讀,
2019年12月28日 清晨6:33:532019/12/28
收件者: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

未讀,
2019年12月28日 清晨6:44:142019/12/28
收件者: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
回覆所有人
回覆作者
轉寄
0 則新訊息