>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 don't quite understand what you mean here. You want me to create a
CategoryModel of which all my Category models should be derived ? If
that's it, how can it help me to determine if URL is valid or not, I
can't see how that works.
>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?
Yes they click links on the webpages :)
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:
>DEBUG is False
>SEND_BROKEN_LINK_EMAILS is True
>Your MIDDLEWARE_CLASSES setting includes CommonMiddleware (which it >does by default).
>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).
Wow that's nice to know, thanks for all these infos !
On Nov 30, 11:15 am, Ivo Brodien <i...@brodien.de> wrote:
> 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:
> DEBUG is False
> SEND_BROKEN_LINK_EMAILS is True
> Your MIDDLEWARE_CLASSES setting includes CommonMiddleware (which it does by default).
> 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
>
> [1]https://docs.djangoproject.com/en/1.3/howto/error-reporting/
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment