I’m trying to get data by id in my django app. The problem is that I don’t know the kind of id the user will click on. I tried adding the below code in my views but I’m getting this error:
ValueError at /findme/
invalid literal for int() with base 10: 'id'
Request Method: GET
Request URL: http://127.0.0.1:8000/findme/
Django Version: 1.4
Exception Type: ValueError
Exception Value: invalid literal for int() with base 10: 'id'
Exception Location: C:\Python27\lib\site-packages\django\db\models\fields\__init__.py in get_prep_value, line 537
Python Executable: C:\Python27\python.exe
Python Version: 2.7.3
Views
from meebapp.models import Meekme
def cribdetail(request):
post=Meekme.objects.get(id='id')
return render_to_response('postdetail.html',{'post':post, 'Meekme':Meekme},context_instance=RequestContext(request))
What I’m I missing?
The problem is that
'id'is a string and you need to pass an integer here:It should most likely look like this:
where
meekme_idis an integer that is part of the URL. Your URL configuration should contain:When you visit
example/3/, that means Django will call the viewcribdetailwith the value 3 assigned tomeekme_id. See the Django URL documentation for more details.