Home > Back-end >  django app.models.VideoLibrary.DoesNotExist: VideoLibrary matching query does not exist
django app.models.VideoLibrary.DoesNotExist: VideoLibrary matching query does not exist

Time:05-03

The problem is I can't type http://localhost:8000/1 to see spesific ViedoLibrary in my database. Can anyone help me to find the solution?

urls.py

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.index, name='index'),
    path('main/', views.main, name='main'),
    path('create_view/', views.create_view, name='create_view'),
    path('list_view/', views.list_view, name='list_view'),
    path('<id>', views.detail_view),
]

views.py

def detail_view(request, id):
    context = {}
    context['data'] = VideoLibrary.objects.get(shop_id=id)
    return render(request, 'app/detail_view.html', context)

models.py

class VideoLibrary(models.Model):
    shop_id = models.AutoField(primary_key=True, unique=True)
    shop_name = models.CharField(max_length=264)
    adress = models.TextField(max_length=264, default='')

Also if I type id=id in views.py the next error pops up : Cannot resolve keyword 'id' into field. Choices are: adress, attendance, equipment, films, genre, income, shop_id, shop_name, staff.

This are all my classes in models.py but there are also adress, shop_id and shop_name that are from specific model

CodePudding user response:

Updated.

You have overriden the id field of your model that is why it won't work with id=id since the latter is actually shop_id. Change it accordingly and it should work.

The id error is telling you that you cannot use id as a field and giving you the list of available model fields you can use for filtering. See this answer for more details. Error: Cannot resolve keyword 'id' into field

  • Related