Django path to current page
I have a django template page, and want a link from this page, containing current URL, for example, I am on /article/11 a开发者_Python百科nd want link to /article/11/remove I tried the following construction:
<a href="{{ request.path }}remove">Remove article</a>
But I get link to /article/remove instead of /article/11/remove However when I change it to
<a href="{{ request.path }}">
I get link to /article/11
How can I get URL not trimmed?
I don't see why it doesn't point you to /article/11remove, which is what it sounds like it should do, but either way, you're missing a slash. Try <a href="{{ request.path }}/remove">
instead.
However, that's really not the right way to do it. You shouldbe using {% url 'name_of_remove_view' %} to get the url, not assuming it's going to be wherever you are plus /remove
.
Edit: In that case, your problem is probably that {{ request.path }} is not outputting anything at all. That would explain why just having "remove" would take you to /article/remove, and having "" would take you to where you currently are, due to the way that relative URLs work. You might want to make sure that you have a request object at all in your template environment.
精彩评论