0

in views.py I have this:

def logout(request,key):
   auth.logout(request)
   return HttpResponseRedirect(reverse('airAgency.views.index',args=[key])) 

in index template i wanna when user click on a link,logout view run:

<a href="{% url airAgency.views.logout %}">logout</a>

I wanna pass key parameter to logout view,Imagine I have an object named agn and it's WebSite field is going to pass to logout view, s.th like this:

<a href="{% url airAgency.views.logout agn.WebSite %}">

Imagine agn.WebSite has the value of mastane above code cause this error:

Caught NoReverseMatch while rendering: Reverse for 'airAgency.views.logout' with arguments '(u'mastane',)' and keyword arguments '{}' not found.

what's the right way to do this?

1 Answer 1

1

Caught NoReverseMatch - usually means that the url is being called by incorrect arguments, or that something else is wrong when {% url %} tries to call the url specified.

You need to define url pattern for that view function to be called in urls.py. And in the url pattern specify a view function.

urls.py

url(r'^logout/(?P<key>[a-zA-Z0-9\-]+)/$', "airAgency.views.logout", name="logout"),

index.html

<a href="{% url logout agn.WebSite %}">

This might not work if you just copy paste it because I don't know the exact project setup.

The key is to have urls.py where regex is used to create patterns for how the url looks like, then a view function that needs to be invoked, and finally a name, which you can then use in your templates.

This is all explained in the basic Django tutorial.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.