Sep-10-2020, 04:20 AM
Hey guys I'm coming along in my project nicely and I'm on to a new issue:
I have all the listings printed on the index page when you log in. You can click on any of these to go to a page about the item. However, only some of these seem to work. About half of them give me this error:
views.py (just the relevant code):
I have all the listings printed on the index page when you log in. You can click on any of these to go to a page about the item. However, only some of these seem to work. About half of them give me this error:
Error:Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/post/g3
Using the URLconf defined in commerce.urls, Django tried these URL patterns, in this order:
admin/
[name='index']
login [name='login']
logout [name='logout']
register [name='register']
auction [name='auction']
watchlist [name='watchlist']
categories [name='categories']
post/<str:title><str:description><int:price><str:category> [name='post']
The current path, post/g3, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
I have no idea why. The others work perfectly and show me all the information about the item. Anyone know why? Below is my code:views.py (just the relevant code):
def post(request, title, description, price, category): title = title description = description price = price category = category query = NewPost.objects.filter(title = title).first() p = {"title": query.title, "description": query.description, "price": query.price, "category": query.category} return render(request, "auctions/post.html", { "p": p})urls.py:
from django.urls import path from . import views 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("auction", views.auction, name="auction"), path("watchlist", views.watchlist, name="watchlist"), path("categories", views.categories, name="categories"), path("post/<str:title><str:description><int:price><str:category>", views.post, name="post") ]models.py:
from django.contrib.auth.models import AbstractUser from django.db import models class User(AbstractUser): pass class NewPost(models.Model): title = models.CharField(max_length=64) description = models.CharField(max_length=64) price = models.IntegerField() category = models.CharField(max_length=64) class Bid(): pass class Comment(): passindex.html:
{% extends "auctions/layout.html" %} {% block body %} <h2>Active Listings</h2> <ul> {% for query in queries %} <li><a href="/post/{{query.title}}{{query.price}}">{{ query.title }} - {{ query.description }} - ${{ query.price }} - {{ query.category }}</a></li> {% endfor %} {% endblock %} </ul>