Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Dec. 3, 2010 12:18:05

R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

main categories in menu


I want to make main categories on my site like:
/main1/page1
/main2/page2
/main3/page3

I would like to make those categories dynamically with a m2m . In that
case I can assign pages to one or more main categories.

I have a problem now with urls.py As far as I know I can only "catch"
one variable like:
(r'^main1/(.*)/$', view), In this way I have to add every main
category manually to urls.py

Is there a way to do something like: (r'^(.*)/(.*)/$', view), (I know
this doesn't work)

Or should I catch everything from the url and try to split the url in
the view?
(r'^(.*)$', view),

A consideration I have that I will end up having double content (which
is bad for Google). Is it also an option to remember the choice made
in a session, and render the menu on page load (through middleware)?



Rob

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 3, 2010 16:56:43

w.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

main categories in menu


On Dec 3, 2:11 am, Rob <r...@wieskamp.nl> wrote:
> I want to make main categories on my site like:
> /main1/page1
> /main2/page2
> /main3/page3

It sounds like you have 3 views, and each one can pick from a pool of
categories. If this is correct, all you need to do is enter a line
for each view (main#), and pass the category (page#) as a variable to
the view, which can then do the lookup. You will use something like:

r'^main1/\w+/$'

which will pass all characters matching the regex (here, alphanumeric
chars) to the view you specify as a positional arg. You can also pass
them as a kwarg. Read here:http://docs.djangoproject.com/en/dev/topics/http/urls/>
> Is there a way to do something like: (r'^(.*)/(.*)/$', view), (I know
> this doesn't work)

To do something like that, instead of wildcarding everything greedily,
just pass a range of characters and symbols you will not accept
(whitespace, etc.) by using in your regex.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Dec. 4, 2010 09:19:06

R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

main categories in menu


> It sounds like you have 3 views, and each one can pick from a pool of
> categories.  If this is correct, all you need to do is enter a line
> for each view (main#), and pass the category (page#) as a variable to
> the view, which can then do the lookup.  You will use something like:
>
Thanks for the reply.

The Problem is that I want to fetch a list of categories from the
database, so the amount of categories could vary. I could add them
manually to urls.py but that's not my preferred way.

So if a user enters mydomain.com/main1/page1 --> check if main1 exists
in the database --> render a menu of all pages which are linked to
main1 --> show page1

Rob

> r'^main1/\w+/$'
>
> which will pass all characters matching the regex (here, alphanumeric
> chars) to the view you specify as a positional arg.  You can also pass
> them as a kwarg.  Read here:  
>http://docs.djangoproject.com/en/dev/topics/http/urls/>
>
>
> > Is there a way to do something like: (r'^(.*)/(.*)/$', view), (I know
> > this doesn't work)
>
> To do something like that, instead of wildcarding everything greedily,
> just pass a range of characters and symbols you will not accept
> (whitespace, etc.) by using in your regex.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Dec. 4, 2010 17:32:31

w.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

main categories in menu


> So if a user enters mydomain.com/main1/page1 --> check if main1 exists
> in the database --> render a menu of all pages which are linked to
> main1 --> show page1

So, I take it that if the user enters the above, and main1 does not
exist in the db, then you will raise an error (probably 404)?

If so, then like I mentioned, it should suffice to do something like:

r'^(?P<main_obj>\w+)/(?P<page_obj>\w+)$', 'view_to_pass_to'

to match against. It will then call the view you specify, and pass
the kwargs main_obj and page_obj. You can then look up these two
slugs in your db, check if they exist, find all page_objs that link to
main_obj, etc.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 Dec. 4, 2010 17:40:43

h.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

main categories in menu


Thank you for explaining.

This is indeed exact what I was looking for. I thought I could only
pass one argument to the view.

Rob

On 4 dec, 18:32, wayne <wayne.tuxro...@gmail.com> wrote:
> > So if a user enters mydomain.com/main1/page1 --> check if main1 exists
> > in the database --> render a menu of all pages which are linked to
> > main1 --> show page1
>
> So, I take it that if the user enters the above, and main1 does not
> exist in the db, then you will raise an error (probably 404)?
>
> If so, then like I mentioned, it should suffice to do something like:
>
> r'^(?P<main_obj>\w+)/(?P<page_obj>\w+)$', 'view_to_pass_to'
>
> to match against.  It will then call the view you specify, and pass
> the kwargs main_obj and page_obj.  You can then look up these two
> slugs in your db, check if they exist, find all page_objs that link to
> main_obj, etc.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 19th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support