Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't pass a variable through my view to the html template

So I’m trying to: pass a variable owner_id in the view def new(request, owner_id) to render new.html that it will be used in the action of a form as a parameter/argument action="{{ url 'new' owner_id }}".

Like This:

def new(request, owner_id):  # from here
if request.method == 'POST':
    ...
else:
    category = Category.objects.all()
    render(request, "auctions/new.html", {
        "category": category,
        "owner_id": owner_id  # <--- to HERE
    })

view.py

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

urls.py

new.html Error detected in this file by django

Layout.html template

Could not parse the remainder

ERROR screenshot

It’s driving me crazy… I can’t understand why its not working.

And the worst part is I already did it on another view and it WORKED!
The only difference is here I use the same variable again inside in the form to "feed" it again, throught the same url, view… etc.
Whether there (another url and view) I used it as a normal variable inside the brakets {{ }}.

PD: I probably lack the basic understanding how django starts to process all this.

>Solution :

A template tag is written between {% and %}, not {{ url 'new' owner_id }}, so:

action="{% url 'new' owner_id %}"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading