[Answered ]-Django user passing

2👍

Url patterns use regular expressions and return the first match. In a regular expression, a ^ signifies the start of a string, and a $ the end. If neither is present, the pattern can be found anywhere in the string and it will still match. Now take a look at your first pattern.

    url(r'', 'views.login'),

This pattern can match anywhere in the string, and it matches if the string “contains” an empty string, i.e. every single string you can think of. All requests will be directed to your views.login view.

To fix it, you must use the pattern r'^$'. This will match the start and the end of the url path with nothing in between, i.e. only www.example.com/ (the first slash is always chopped of). Then you can reach your other views at /logout/ and /main/.

👤knbk

Leave a comment