I have a same template that is used for different urls (in this case: /create/ and /edit/[PK of an item] , named “create” and “edit” in the url.py).
I would like to show different things in my template depending if I’m on /edit/ or /create/.
How can I check this ?
{% if '/create' in request.path %} works, but I’d like to use a url tag (or equivalent, to not have it “hard coded”).
What I would like to do looks like (in pseudo code – this doesn’t work) {% if request.path in url create %} XXX {% endif %}.
Should I make all the necessary tests in the views.py, send a variable about it in the context, test on this variable in the template? In my case it seems a bit heavy for a simple url test …
I’d say go for making two views if it’s a significant difference (different form, etc.) – eliminates url logic in templates entirely, and no real ‘test’ needed either – don’t have to check request.path/pass url/etc.
urls
views
template
Can also pass multiple changes easily with a list this way too:
views
template