404 for some matching urls too (Version 2)

48 views
Skip to first unread message

Sundararajan Seshadri

unread,
Dec 29, 2017, 7:09:15 AM12/29/17
to Django users
I do not know the mistake I am likely to be committing. In Django Version 2, I have a feeling that URL matching fails whenever there are query variables. 

When I try to log into Admin module, the login screen comes. But when a 'next' query variable is attached, I get a 404. Similarly when I try to jump to a page in the records listing, I get 404. (Color has been added for highlighting)


Using the URLconf defined in sundar.urls, Django tried these URL patterns, in this order:

admin/ [name='index']
admin/ login/ [name='login']
admin/ logout/ [name='logout']
admin/ password_change/ [name='password_change']
admin/ password_change/done/ [name='password_change_done']
admin/ jsi18n/ [name='jsi18n']
admin/ r/<int:content_type_id>/<path:object_id>/ [name='view_on_site']
...... (corresponds to the tables defined)
admin/ ^(?P<app_label>rsi|auth)/$ [name='app_list']
login/ [name='login']
logout/ [name='logout']
authissue [name='authissue']
.....

The current path, admin/login/?next=/admin/, didn't match any of these.

Any help is appreciated.



Matemática A3K

unread,
Dec 29, 2017, 10:10:17 AM12/29/17
to django...@googlegroups.com
Please post your urls.py, this looks strange:

admin/ [name='index']
admin/ login/ [name='login']
admin/ logout/ [name='logout']
admin/ r/<int:content_type_id>/<path:object_id>/ [name='view_on_site']

James Schneider

unread,
Dec 29, 2017, 1:22:53 PM12/29/17
to django...@googlegroups.com


admin/ [name='index']
admin/ login/ [name='login']
admin/ logout/ [name='logout']
admin/ password_change/ [name='password_change']
admin/ password_change/done/ [name='password_change_done']
admin/ jsi18n/ [name='jsi18n']
admin/ r/<int:content_type_id>/<path:object_id>/ [name='view_on_site']
...... (corresponds to the tables defined)
admin/ ^(?P<app_label>rsi|auth)/$ [name='app_list']
login/ [name='login']
logout/ [name='logout']
authissue [name='authissue']
.....

The current path, admin/login/?next=/admin/, didn't match any of these.

It looks like you have two different URL's named 'login'. Try changing one of them so that they are unique.

-James

Sundararajan Seshadri

unread,
Dec 31, 2017, 10:25:54 AM12/31/17
to Django users
Thanks for the support and responses.

The error was due to an interesting line of code. 

I had a middleware where I used:

match = resolve(request.get_full_path()) and this was causing the error I mentioned.(get_full_path returns the query string too.)

I replaced it with

match = resolve(request.path_info)

and it is now working fine. Something to do with internal working? Any simple explanation for my curiosity will be welcome. 

Thanks everybody.
========================================================================

James Schneider

unread,
Jan 2, 2018, 4:13:35 AM1/2/18
to django...@googlegroups.com


On Dec 31, 2017 7:26 AM, "Sundararajan Seshadri" <sun...@gmail.com> wrote:
Thanks for the support and responses.

The error was due to an interesting line of code. 

I had a middleware where I used:

match = resolve(request.get_full_path()) and this was causing the error I mentioned.(get_full_path returns the query string too.)

I replaced it with

match = resolve(request.path_info)

and it is now working fine. Something to do with internal working? Any simple explanation for my curiosity will be welcome. 

Thanks everybody.

To me, this seems like intended and correct behavior. The URL dispatcher does not normally receive paths that include the query string. The query string is parsed separately and populates other portions of the request object such as request.GET and request.POST.


I'm not familiar with the resolve() function, but I assume it is calling the Django URL dispatch process.

-James
Reply all
Reply to author
Forward
0 new messages