I am building a django (v3.2.5) project called commerce which has an app called auctions.
urls.py for commerce:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path("admin/", admin.site.urls),
path("", include("auctions.urls"))
]
urls.py of auctions: (notice that watchlist path is commented out)
from django.urls import path
from . import views
app_name = 'auctions'
urlpatterns = [
path("", views.index, name="index"),
path("login", views.login_view, name="login"),
path("logout", views.logout_view, name="logout"),
path("register", views.register, name="register"),
path("create", views.create, name='create'),
path("listing/<int:listing_id>/", views.listing, name='listing'),
# path("watchlist/", views.watchlist, name='watchlist')
]
views.py: (watchlist function is commented out)
@login_required(login_url='/login')
def listing(request, listing_id):
if request.method == 'GET':
listing_data = list(Listing.objects.filter(id = listing_id))
return render(request, "auctions/listing.html", context={"listings":listing_data})
else:
pass
# @login_required(login_url='/login')
# def watchlist(request):
# pass
index.html:
<a href="{% url 'auctions:listing' listing.id %}" class="btn btn-primary">View Listing</a>
This is the only tag that points to the listing function/path in views.py. No tag points to the watchlist function/path.
This is the error message when I click on the above tag to go to listing.html enter image description here
The error points to this particular line of code in views.py:
return render(request, "auctions/listing.html", context={"listings":listing_data})
Whenever I remove the context dictionary, that is put only the request and the template in render(),the code runs perfectly fine and gives me listing.html, but of course without the data.
return render(request, "auctions/listing.html")
The above works perfectly fine and renders.
This code was working fine until I began developing the watchlist feature. Despite watchlist being commented out in urls.py, views.py and the templates, the issue still persisted. I added 'app_name=auctions' in urls.py. I tried using a form instead of an anchor tag.