Reputation: 1029
What's the most appropriate way to modify HTML content in views with nested URL structures?
For instance, let's say that I have an Index page that serves up selection options for three cats ["Small","Medium","Large"]. When a user selects "Small", we can redirect the user to the default/Small
view. This view then serves up some additional selection options, like ["Happy","Sad","Mad"]. When a user selects an option here, say "Happy", we can build that selection option into the url via args so now the URL becomes default/Small/Happy
. However, if I then create a default/Small/Happy
view with some additional selection options to serve to the user, the page does not show the new content (it still shows the content from default/Small
). In the end, I'd like to take all of the args, "Small", "Happy", etc., build a query and serve up some results to the user from the database.
I obviously don't fully understand how this works, so I just need a little guidance.
Upvotes: 0
Views: 114
Reputation: 25536
The best approach depends on exactly what needs to differ in the view based on the different categories. Let's say you have a URL like /myapp/default/index/Small/Happy
. In the index
function, you could do something like:
def index():
size = request.args(0)
emotion = request.args(1)
data = [code based on size and emotion]
return dict(size=size, emotion=emotion, data=data)
If you need to create different displays in the view depending on the categories, you can include conditional logic.
In /views/default/index.html:
{{if size == 'Small':}}
HTML for the small display
{{elif size == 'Medium':}}
...
{{pass}}
Upvotes: 1