Getting NoReverseMatch at /logout/

242 views
Skip to first unread message

Deepanshu Sagar

unread,
Mar 28, 2016, 5:49:20 AM3/28/16
to Django users
Hello,

I am getting below error while clicking on logout button on webpage:


boardgames/url.py contains:


main/urls.py and views.py are below.




please guys, any help is appreciated.

Regards
Deepanshu
Auto Generated Inline Image 1
Auto Generated Inline Image 2
Auto Generated Inline Image 3
Auto Generated Inline Image 4

monoBOT

unread,
Mar 28, 2016, 7:09:34 AM3/28/16
to django...@googlegroups.com
That url doesnt exist on your urls.py

looks like you are trying to navigate to "boardgames_home"
when trying to access the "/" url

name is for reverse lookups from inside the django app not for the urls.

Deepanshu

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8fbe6e38-84c9-4ccb-b0e1-b91eade1b036%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
monoBOT
Visite mi sitio(Visit my site): monobotsoft.es/blog/

Deepanshu Sagar

unread,
Mar 28, 2016, 7:31:45 AM3/28/16
to Django users
Oh okay,

So, If I want to navigate to home page, which is at '/', how do it give the parameter for this along with next_page key-value pair?
url(r'^logout/$', auth_views.logout, {'next_page': 'boardgames_home'}, name='boardgames_logout'),

Thank you for the reply though.

Regards
Deepanshu

ludovic coues

unread,
Mar 28, 2016, 8:10:07 AM3/28/16
to django...@googlegroups.com
Your problem might be mixing include and name in the urls.py file.
reverse("home") should give you better result.


For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

Vadim Serdiuk

unread,
Mar 28, 2016, 9:26:21 AM3/28/16
to Django users
Hello.
The exception raises because 'boardgames_home' name is defined for group of patterns, and not one.
So it was skiped and is undefined in runtime. 
Use 'name' parameter only for individual pattern, don't use it when include other patterns. 

Also don't use blank string in url pattern. Use '/' for home page instead of ''.

понедельник, 28 марта 2016 г., 12:49:20 UTC+3 пользователь Deepanshu Sagar написал:

James Schneider

unread,
Mar 28, 2016, 1:23:22 PM3/28/16
to django...@googlegroups.com
On Mon, Mar 28, 2016 at 6:26 AM, Vadim Serdiuk <va.se...@gmail.com> wrote:
Hello.
The exception raises because 'boardgames_home' name is defined for group of patterns, and not one.
So it was skiped and is undefined in runtime. 
Use 'name' parameter only for individual pattern, don't use it when include other patterns. 

That's not entirely accurate. It is perfectly valid to assign a name to an included set of URL's. This creates a namespace for the URL's that are being included. See here:


The OP is incorrectly trying to reverse the parent namespace ('boardgames_home') rather than the full name of the URL in question ('boardgames_home:home' per the current namespace setup), which can't be resolved directly because the parent namespace refers to an include() for zero or more other patterns.
 

Also don't use blank string in url pattern. Use '/' for home page instead of ''.


Correct, using an empty string will definitely cause you problems down the road. With an empty string and the current ordering of the URL definitions, I believe URL matching for login/ and logout/ will fail consistently. 

-James

James Schneider

unread,
Mar 28, 2016, 2:17:14 PM3/28/16
to django...@googlegroups.com
On Mon, Mar 28, 2016 at 2:49 AM, Deepanshu Sagar <deepa...@gmail.com> wrote:
Hello,

I am getting below error while clicking on logout button on webpage:




Hmm, you cut off the interesting stuff underneath this section. The traceback information below is usually super helpful. 

 
boardgames/url.py contains:



As mentioned in the other responses, an empty string should not be used in your regular expression list of URL's. It will match every single URL search, which is likely not what you want. You'll want to use just a '/' as others have suggested. However, if you only plan to have the single URL as part of your include, you may want to consider just importing the view from your app back into the above urls.py file and referencing it directly.

You may also want to move that particular entry to the bottom of the list so that your auth URL's are searched first, in the event there is any overlap down the road. 

 
main/urls.py and views.py are below.



Combine this with your boardgames/urls.py above, and the name of this URL is actually 'boardgames_home:home' give the URL namespacing you've created.

I included this link in my other response, but I'll put it here for completeness:


 




This particular snippet doesn't appear to be relevant. The culprit causing the error is likely in your template code (probably a {% url 'home' %} tag). You'll need to either 

  • Tweak your urls.py files to eliminate the namespacing (remove the name= reference on your include() URL. 
  • Update your {% url %} and reverse() calls to include the namespace that you've provided ('boardgames_home:home'). 
-James

Prasanthi Paladugu

unread,
Mar 28, 2016, 2:52:46 PM3/28/16
to django...@googlegroups.com
It's a namespace collision 

Kindly take a look over it "home" and boardgames_homes tearing a part.

simply remove the namespace that is occurring at the include section.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

knbk

unread,
Mar 28, 2016, 6:08:57 PM3/28/16
to Django users


On Monday, March 28, 2016 at 7:23:22 PM UTC+2, James Schneider wrote:
That's not entirely accurate. It is perfectly valid to assign a name to an included set of URL's. This creates a namespace for the URL's that are being included. See here:

Actually, the name parameter is completely ignored[1] when using include(). You can set a namespace by passing the namespace (and app_nameparameter to include()[2], or in 1.9+, by setting the app_name attribute in the target URLconf[3]. That means the name that should be used with the current code is just 'home'.

James Schneider

unread,
Mar 28, 2016, 6:21:53 PM3/28/16
to django...@googlegroups.com

On Monday, March 28, 2016 at 7:23:22 PM UTC+2, James Schneider wrote:
That's not entirely accurate. It is perfectly valid to assign a name to an included set of URL's. This creates a namespace for the URL's that are being included. See here:

Actually, the name parameter is completely ignored[1] when using include(). You can set a namespace by passing the namespace (and app_nameparameter to include()[2], or in 1.9+, by setting the app_name attribute in the target URLconf[3]. That means the name that should be used with the current code is just 'home'.


I really need to read the code closer. I simply read it as 'namespace' in my head. You are correct.

-James 
Reply all
Reply to author
Forward
0 new messages