Python Forum
Issue with Django only some links work?
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue with Django only some links work?
#1
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:

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():
    pass
index.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>
Reply


Messages In This Thread
Issue with Django only some links work? - by card51shor - Sep-10-2020, 04:20 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020