Django urls - how to traverse multiple directories through a clean url unnecessarily?
I want to stay on track from the GET parameters. Don't want to use POST and I have at least two different categories to generate the url.
Visitors are first asked to select a location, which can be one of, for example: http://foo.com/United-States/ || http://foo.com/United-States/California/ || http://foo.com/United-States/California/San-Francisco-Region/ || http://foo.com/United-States/California/San-Francisco/
After choosing a location, they can choose a category, which can be one of the following:
http://foo.com/Electronics/ || http://foo.com/Electronics/Camera/ || http://foo.com/Electronics/Camera/Digital/ || http://foo.com/Electronics/Camera/Digital/SLR/
So how could I combine both of the above urls into one, once done with location and category selection?
I may need to pass the page number for pagination. ( http://foo.com/page/2/ )
I want the URL to be clean and clear. I know how to make one type of URL at a time, but not combine multiple types.
If I did a GET, then I would do: http://foo.com/?locid=23323&catid=335&page=2 , but I like to use Django clean url and stay out of the & stuff.
Thanks,
VN44CA
a source to share
I think this will go to a lot of information in the url. I am assuming that any location has its own unique identifier, the same applies to the category. Why not create a url:
http://foo.com/United-States/Electronics/
http://foo.com/California/Digital/
http://foo.com/San-Francisco/SLR/
etc.
In your case, 2 arguments are enough. Or, you can change the category name to be more meaningful.
http://foo.com/Electronics/Camera/Digital/ => http://foo.com/Digital-Cameras/
a source to share
Depending on how you use the location data and how often the user wants to change the location, it is best to store it in the session rather than being specified in the URL.
For example, I’m not likely to start looking for SLR cameras in San Francisco and then go looking for basketball in Baltimore.
Obviously this won't be enough if you want to have a permalink to any combination of location categories.
a source to share
After thinking about this for a while, I found that the best solution for me is to have a string containing all the arguments I need in a clean url.
So, when users first come to http://foo.com/ , they are presented with locations to choose from. At the moment the cookies are empty.
So the user goes ahead and selects United-State, the url will look like http://foo.com/12334_0_0_0/United-States/ and the location cookie is set to 1234 which is the US location ID.
The user now selects California and the URL changes to http://foo.com/1235_0_0_0/United-States-California/ and the cookie changes from United States to 1235, which is the identifier for the California location. At this point, the user selects an electronics category. therefore the url is changed to http://foo.com/1235_3333_0_0/Electronics/ and 3333 is saved in the Cookies category.
If users go down to SLR Camera then he / she will see http://foo.com/1235_3344_0_0/SLR-Cameras/ .
So the first part of the url keeps track of up to 4 arguments that can be passed, and the names (bullets) are just for presentation and SEO.
I think this will work right? It would be great to have the x_y_z_p portion of the url encoded into some random text and decode back into arguments and numbers.
Let me know what you think?
a source to share