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?
#11
(Sep-13-2020, 05:00 AM)card51shor Wrote: Obviously it's not finding a match in the database when I do the query.

Are you getting the same error now as in the first post? If so, if you'd taken time to read the error message properly, you'd see that it's not even getting to the database; the request handling is failing.
Reply
#12
The ones that have a title, description, or category that were entered with a lowercase first letter get 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.
Which I assume is not matching because I entered it before I thought of matching case. I can fix that easy.

The ones that have the error I cant' figure out have this error:

Error:
AttributeError at /post/Keyboard20 'NoneType' object has no attribute 'description' Request Method: GET Request URL: http://127.0.0.1:8000/post/Keyboard20 Django Version: 3.0.8 Exception Type: AttributeError Exception Value: 'NoneType' object has no attribute 'description' Exception Location: C:\school\project2\commerce\auctions\views.py in post, line 93 Python Executable: C:\Python38\python.exe Python Version: 3.8.2 Python Path: ['C:\\school\\project2\\commerce', 'C:\\Python38\\python38.zip', 'C:\\Python38\\DLLs', 'C:\\Python38\\lib', 'C:\\Python38', 'C:\\Python38\\lib\\site-packages'] Server time: Sun, 13 Sep 2020 05:09:48 +0000 Traceback Switch to copy-and-paste view C:\Python38\lib\site-packages\django\core\handlers\exception.py in inner response = get_response(request) … ▶ Local vars C:\Python38\lib\site-packages\django\core\handlers\base.py in _get_response response = self.process_exception_by_middleware(e, request) … ▶ Local vars C:\Python38\lib\site-packages\django\core\handlers\base.py in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) … ▶ Local vars C:\school\project2\commerce\auctions\views.py in post print(query.description) … ▼ Local vars Variable Value category '0' description 'D' price 2 query None request <WSGIRequest: GET '/post/Keyboard20'> title 'Keyboar'
it had the title missing the last letter and the first letter as the description. I can't figure out exactly where the error is - has to be in views.py somewhere.

Here is a photo of all the actual listings and their 4 fields filled out:

[Image: JqQjzQV.png]

The ones that work are the Playstation, Monkey, And Jacky
Reply
#13
So, what information are you getting from the error message? If your initial thought is again, "nothing", spend some time gathering info from there. This is literally what any of the rest of us would do.
Reply
#14
I get that it's assigning the variables wrong. The reason? I don't know.

I've looked it over a bunch. Can u tell me what the problem is?

Do u think you know what it is? Or is it something that I have to find by doing more research?
Reply
#15
(Sep-13-2020, 05:30 AM)card51shor Wrote: I get that it's assigning the variables wrong.

Which variables? What values do they have and what do you expect them to have? Where do those variables get assigned their values?

Quote:The reason? I don't know.

Sometimes I won't know immediately why my code isn't working, but I don't just stop - I use the information available to me to work out why.

Quote:I've looked it over a bunch. Can u tell me what the problem is?

Do u think you know what it is? Or is it something that I have to find by doing more research?

At this point, I'm where you are.

(Sep-13-2020, 05:00 AM)card51shor Wrote: Well it would be impossible to list all the things I've done - I just tried a bunch of different methods but can't get it to work.

Think about this: we aren't at the computer with you so can't see what you've tried. If we suggest things that you've already tried, that's not a good use of anyone's time is it?
Reply
#16
OK take the Keyboard entry. It says the title is "Keyboar" instead of "Keyboard" and puts the extra "D" as the description. Then it has the price as the first digit of the price and the category as the second digit of the price.

I'm not sure why it does this for the Keyboard entry but it works fine for the Monkey, Playstation and Jacky entry. Do u know why? Are you trying to figure it out along with me?

I'm not stopping - I'm trying to figure it out. I don't see the problem though. If I don't see the problem - what do I do? I've been working on it for over a day.
Reply
#17
(Sep-13-2020, 05:58 AM)card51shor Wrote: OK take the Keyboard entry. It says the title is "Keyboar" instead of "Keyboard" and puts the extra "D" as the description. Then it has the price as the first digit of the price and the category as the second digit of the price.

Ok, I think this is a bit of progress. So, where do the title, description, price and category come from? I mean, where in the code are those variables populated with the values?

Quote:I'm not sure why it does this for the Keyboard entry but it works fine for the Monkey, Playstation and Jacky entry. Do u know why? Are you trying to figure it out along with me?

I'm pretty much trying to work it out with you. This is a bit of a strange problem right now and I don't have the data, so I'm relying on you.

Quote:If I don't see the problem - what do I do? I've been working on it for over a day.

I guess we just need to make sure that you have the tools of taking baby steps to work out the problems. That along with fresh eyes usually helps. Also, have you heard the term "rubber duck"? That's what I'm trying to do here. Getting one to explain their thoughts and things often leads to a Eureka moment.
Reply
#18
they're in a Django database that I have written in the Models.py file.

Here they are:


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
Reply
#19
This is good. Now, do you have a way to look at what's stored in the database directly (command line tools for whichever database this is, or whatever you normally use)? If so, just post the output here. I want to do that to rule in or out the possibility of something funny going on between reading the data out and it getting on the page.
Reply
#20
the picture i posted earlier shows the list of all the entries. I have it getting everything and outputting it to the active listings page.

Here it is:

[Image: JqQPPHT.png]
Reply


Forum Jump:

User Panel Messages

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