Wednesday, November 30, 2011

Re: A view associated with a lot of urls

Hi,

That's why I'm
considering checking at the beginning of the view with a list/dict
filled with category names and one filled with item names to make sure
that the category is in the list/dict and same for the item before
hitting the database, and if not respond with a 404.

As Reinout suggested you should have a CategoryModel which you can check if a Category exists and the get the items of show that the category does not exist or 404 if somebody entered a wrong URL/Category. Checking against the DB is probably the same thing you want to do, but it uses the DB and not a List/Dict which you have to maintain manually somehow.

I think you care too much about people entering wrong URLs. People are clicking links on your webpage, right? Or do you give him instructions to write urls in the adress field?

As long as you produce correct urls the code works and only should show 404 if someone messed with the URL.

Consider doing this:

1) use the url tag or get_absolute_url of your models to produce the urls in your template
2) configure your site to send you 404 errors which have a referer (read below and [1])

404 errors

Django can also be configured to e-mail errors about broken links (404 "page not found" errors). Django sends e-mails about 404 errors when:
If those conditions are met, Django will e-mail the users listed in the MANAGERS setting whenever your code raises a 404 and the request has a referer. (It doesn't bother to e-mail for 404s that don't have a referer – those are usually just people typing in broken URLs or broken Web 'bots).


bye


No comments:

Post a Comment