We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
The new learners and coachs account, can't view the kolibri 0.11.0a3 at first login
<!--
Instructions:
 * Fill out the sections below, replace …'s with information about your issue
 * Use the 'preview' function above this text box to verify formatting before submitting
-->

### Observed behavior
When I create a learners account and test to login, the page show like this "The requested URL / was not found on this server."

<!--
Description of the behavior that was observed, including screenshots or other references when applicable
-->



### Expected behavior
Must login to kolibri page.
<!--
Description of what behavior was expected but did not occur
-->


### Errors and logs
```
The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol. 127.0.0.1:8080 
```
<!--
Relevant logs from:
 * the command line
 * ~/.kolibri/kolibri.log
 * the browser console

Please wrap errors in triple backticks for clean formatting like this:
```
01:10 info: something happened
01:12 error: something bad happened
```
-->

…

### Steps to reproduce
1. login with admin account
2. go to facility and user tab
3. create new learner account
4. try to login the new learner account and see the error page.
<!--
Precise steps that someone else can follow in order to see this behavior
-->

…

### Context
Windows 7 and 10
kolibri 0.11.0a3
firefox 61.0.1(64-bit)
<!--
Tell us about your environment, including:
 * Kolibri version
 * Operating system
 * Browser
-->
### Screenshot
![errorloginpage](https://user-images.githubusercontent.com/38421180/42367122-fb1ae096-80b7-11e8-9165-6e73b2702a72.png)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `kolibri/core/views.py`
Content:
```
1 from django import http
2 from django.conf import settings
3 from django.contrib.auth import logout
4 from django.core.urlresolvers import translate_url
5 from django.http import Http404
6 from django.http import HttpResponseRedirect
7 from django.utils.http import is_safe_url
8 from django.utils.translation import check_for_language
9 from django.utils.translation import LANGUAGE_SESSION_KEY
10 from django.utils.translation import ugettext_lazy as _
11 from django.views.generic.base import View
12 from django.views.i18n import LANGUAGE_QUERY_PARAMETER
13 
14 from kolibri.core.auth.constants import user_kinds
15 from kolibri.core.auth.models import Role
16 from kolibri.core.decorators import signin_redirect_exempt
17 from kolibri.core.hooks import RoleBasedRedirectHook
18 
19 
20 # Modified from django.views.i18n
21 @signin_redirect_exempt
22 def set_language(request):
23     """
24     Redirect to a given url while setting the chosen language in the
25     session or cookie. The url and the language code need to be
26     specified in the request parameters.
27     Since this view changes how the user will see the rest of the site, it must
28     only be accessed as a POST request. If called as a GET request, it will
29     redirect to the page in the request (the 'next' parameter) without changing
30     any state.
31     """
32     next = request.POST.get('next', request.GET.get('next'))
33     if not is_safe_url(url=next, host=request.get_host()):
34         next = request.META.get('HTTP_REFERER')
35         if not is_safe_url(url=next, host=request.get_host()):
36             next = '/'
37     response = http.HttpResponseRedirect(next)
38     if request.method == 'POST':
39         lang_code = request.POST.get(LANGUAGE_QUERY_PARAMETER)
40         if lang_code and check_for_language(lang_code):
41             next_trans = translate_url(next, lang_code)
42             if next_trans != next:
43                 response = http.HttpResponseRedirect(next_trans)
44             if hasattr(request, 'session'):
45                 request.session[LANGUAGE_SESSION_KEY] = lang_code
46             # Always set cookie
47             response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code,
48                                 max_age=settings.LANGUAGE_COOKIE_AGE,
49                                 path=settings.LANGUAGE_COOKIE_PATH,
50                                 domain=settings.LANGUAGE_COOKIE_DOMAIN)
51     return response
52 
53 
54 def logout_view(request):
55     logout(request)
56     return http.HttpResponseRedirect('/')
57 
58 
59 def get_url_by_role(role, first_login):
60     obj = next((hook for hook in RoleBasedRedirectHook().registered_hooks
61                 if hook.role == role and hook.first_login == first_login), None)
62     if obj:
63         return obj.url
64 
65 
66 class GuestRedirectView(View):
67     def get(self, request):
68         """
69         Redirects a guest user to a learner accessible page.
70         """
71         return HttpResponseRedirect(get_url_by_role(user_kinds.LEARNER, False))
72 
73 
74 class RootURLRedirectView(View):
75 
76     def get(self, request):
77         """
78         Redirects user based on the highest role they have for which a redirect is defined.
79         """
80         first_login = request.session.get("first_login", False)
81         if request.user.is_authenticated():
82             url = None
83             if request.user.is_superuser:
84                 url = url or get_url_by_role(user_kinds.SUPERUSER, first_login)
85             roles = set(Role.objects.filter(user_id=request.user.id).values_list('kind', flat=True).distinct())
86             if user_kinds.ADMIN in roles:
87                 url = url or get_url_by_role(user_kinds.ADMIN, first_login)
88             if user_kinds.COACH in roles:
89                 url = url or get_url_by_role(user_kinds.COACH, first_login)
90             url = url or get_url_by_role(user_kinds.LEARNER, first_login)
91         else:
92             url = get_url_by_role(user_kinds.ANONYMOUS, first_login)
93         if url:
94             return HttpResponseRedirect(url)
95         raise Http404(_("No appropriate redirect pages found, it is likely that Kolibri is badly configured"))
96
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/kolibri/core/views.py b/kolibri/core/views.py
--- a/kolibri/core/views.py
+++ b/kolibri/core/views.py
@@ -59,6 +59,13 @@
 def get_url_by_role(role, first_login):
     obj = next((hook for hook in RoleBasedRedirectHook().registered_hooks
                 if hook.role == role and hook.first_login == first_login), None)
+
+    if obj is None and first_login:
+        # If it is the first_login, do a fallback to find the non-first login behaviour when it is
+        # not available
+        obj = next((hook for hook in RoleBasedRedirectHook().registered_hooks
+                    if hook.role == role and hook.first_login is False), None)
+
     if obj:
         return obj.url

{"golden_diff": "diff --git a/kolibri/core/views.py b/kolibri/core/views.py\n--- a/kolibri/core/views.py\n+++ b/kolibri/core/views.py\n@@ -59,6 +59,13 @@\n def get_url_by_role(role, first_login):\n     obj = next((hook for hook in RoleBasedRedirectHook().registered_hooks\n                 if hook.role == role and hook.first_login == first_login), None)\n+\n+    if obj is None and first_login:\n+        # If it is the first_login, do a fallback to find the non-first login behaviour when it is\n+        # not available\n+        obj = next((hook for hook in RoleBasedRedirectHook().registered_hooks\n+                    if hook.role == role and hook.first_login is False), None)\n+\n     if obj:\n         return obj.url\n", "issue": "The new learners and coachs account, can't view the kolibri 0.11.0a3 at first login\n<!--\r\nInstructions:\r\n * Fill out the sections below, replace \u2026's with information about your issue\r\n * Use the 'preview' function above this text box to verify formatting before submitting\r\n-->\r\n\r\n### Observed behavior\r\nWhen I create a learners account and test to login, the page show like this \"The requested URL / was not found on this server.\"\r\n\r\n<!--\r\nDescription of the behavior that was observed, including screenshots or other references when applicable\r\n-->\r\n\r\n\r\n\r\n### Expected behavior\r\nMust login to kolibri page.\r\n<!--\r\nDescription of what behavior was expected but did not occur\r\n-->\r\n\r\n\r\n### Errors and logs\r\n```\r\nThe character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol. 127.0.0.1:8080 \r\n```\r\n<!--\r\nRelevant logs from:\r\n * the command line\r\n * ~/.kolibri/kolibri.log\r\n * the browser console\r\n\r\nPlease wrap errors in triple backticks for clean formatting like this:\r\n```\r\n01:10 info: something happened\r\n01:12 error: something bad happened\r\n```\r\n-->\r\n\r\n\u2026\r\n\r\n### Steps to reproduce\r\n1. login with admin account\r\n2. go to facility and user tab\r\n3. create new learner account\r\n4. try to login the new learner account and see the error page.\r\n<!--\r\nPrecise steps that someone else can follow in order to see this behavior\r\n-->\r\n\r\n\u2026\r\n\r\n### Context\r\nWindows 7 and 10\r\nkolibri 0.11.0a3\r\nfirefox 61.0.1(64-bit)\r\n<!--\r\nTell us about your environment, including:\r\n * Kolibri version\r\n * Operating system\r\n * Browser\r\n-->\r\n### Screenshot\r\n![errorloginpage](https://user-images.githubusercontent.com/38421180/42367122-fb1ae096-80b7-11e8-9165-6e73b2702a72.png)\r\n\n", "before_files": [{"content": "from django import http\nfrom django.conf import settings\nfrom django.contrib.auth import logout\nfrom django.core.urlresolvers import translate_url\nfrom django.http import Http404\nfrom django.http import HttpResponseRedirect\nfrom django.utils.http import is_safe_url\nfrom django.utils.translation import check_for_language\nfrom django.utils.translation import LANGUAGE_SESSION_KEY\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.views.generic.base import View\nfrom django.views.i18n import LANGUAGE_QUERY_PARAMETER\n\nfrom kolibri.core.auth.constants import user_kinds\nfrom kolibri.core.auth.models import Role\nfrom kolibri.core.decorators import signin_redirect_exempt\nfrom kolibri.core.hooks import RoleBasedRedirectHook\n\n\n# Modified from django.views.i18n\n@signin_redirect_exempt\ndef set_language(request):\n    \"\"\"\n    Redirect to a given url while setting the chosen language in the\n    session or cookie. The url and the language code need to be\n    specified in the request parameters.\n    Since this view changes how the user will see the rest of the site, it must\n    only be accessed as a POST request. If called as a GET request, it will\n    redirect to the page in the request (the 'next' parameter) without changing\n    any state.\n    \"\"\"\n    next = request.POST.get('next', request.GET.get('next'))\n    if not is_safe_url(url=next, host=request.get_host()):\n        next = request.META.get('HTTP_REFERER')\n        if not is_safe_url(url=next, host=request.get_host()):\n            next = '/'\n    response = http.HttpResponseRedirect(next)\n    if request.method == 'POST':\n        lang_code = request.POST.get(LANGUAGE_QUERY_PARAMETER)\n        if lang_code and check_for_language(lang_code):\n            next_trans = translate_url(next, lang_code)\n            if next_trans != next:\n                response = http.HttpResponseRedirect(next_trans)\n            if hasattr(request, 'session'):\n                request.session[LANGUAGE_SESSION_KEY] = lang_code\n            # Always set cookie\n            response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code,\n                                max_age=settings.LANGUAGE_COOKIE_AGE,\n                                path=settings.LANGUAGE_COOKIE_PATH,\n                                domain=settings.LANGUAGE_COOKIE_DOMAIN)\n    return response\n\n\ndef logout_view(request):\n    logout(request)\n    return http.HttpResponseRedirect('/')\n\n\ndef get_url_by_role(role, first_login):\n    obj = next((hook for hook in RoleBasedRedirectHook().registered_hooks\n                if hook.role == role and hook.first_login == first_login), None)\n    if obj:\n        return obj.url\n\n\nclass GuestRedirectView(View):\n    def get(self, request):\n        \"\"\"\n        Redirects a guest user to a learner accessible page.\n        \"\"\"\n        return HttpResponseRedirect(get_url_by_role(user_kinds.LEARNER, False))\n\n\nclass RootURLRedirectView(View):\n\n    def get(self, request):\n        \"\"\"\n        Redirects user based on the highest role they have for which a redirect is defined.\n        \"\"\"\n        first_login = request.session.get(\"first_login\", False)\n        if request.user.is_authenticated():\n            url = None\n            if request.user.is_superuser:\n                url = url or get_url_by_role(user_kinds.SUPERUSER, first_login)\n            roles = set(Role.objects.filter(user_id=request.user.id).values_list('kind', flat=True).distinct())\n            if user_kinds.ADMIN in roles:\n                url = url or get_url_by_role(user_kinds.ADMIN, first_login)\n            if user_kinds.COACH in roles:\n                url = url or get_url_by_role(user_kinds.COACH, first_login)\n            url = url or get_url_by_role(user_kinds.LEARNER, first_login)\n        else:\n            url = get_url_by_role(user_kinds.ANONYMOUS, first_login)\n        if url:\n            return HttpResponseRedirect(url)\n        raise Http404(_(\"No appropriate redirect pages found, it is likely that Kolibri is badly configured\"))\n", "path": "kolibri/core/views.py"}], "after_files": [{"content": "from django import http\nfrom django.conf import settings\nfrom django.contrib.auth import logout\nfrom django.core.urlresolvers import translate_url\nfrom django.http import Http404\nfrom django.http import HttpResponseRedirect\nfrom django.utils.http import is_safe_url\nfrom django.utils.translation import check_for_language\nfrom django.utils.translation import LANGUAGE_SESSION_KEY\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.views.generic.base import View\nfrom django.views.i18n import LANGUAGE_QUERY_PARAMETER\n\nfrom kolibri.core.auth.constants import user_kinds\nfrom kolibri.core.auth.models import Role\nfrom kolibri.core.decorators import signin_redirect_exempt\nfrom kolibri.core.hooks import RoleBasedRedirectHook\n\n\n# Modified from django.views.i18n\n@signin_redirect_exempt\ndef set_language(request):\n    \"\"\"\n    Redirect to a given url while setting the chosen language in the\n    session or cookie. The url and the language code need to be\n    specified in the request parameters.\n    Since this view changes how the user will see the rest of the site, it must\n    only be accessed as a POST request. If called as a GET request, it will\n    redirect to the page in the request (the 'next' parameter) without changing\n    any state.\n    \"\"\"\n    next = request.POST.get('next', request.GET.get('next'))\n    if not is_safe_url(url=next, host=request.get_host()):\n        next = request.META.get('HTTP_REFERER')\n        if not is_safe_url(url=next, host=request.get_host()):\n            next = '/'\n    response = http.HttpResponseRedirect(next)\n    if request.method == 'POST':\n        lang_code = request.POST.get(LANGUAGE_QUERY_PARAMETER)\n        if lang_code and check_for_language(lang_code):\n            next_trans = translate_url(next, lang_code)\n            if next_trans != next:\n                response = http.HttpResponseRedirect(next_trans)\n            if hasattr(request, 'session'):\n                request.session[LANGUAGE_SESSION_KEY] = lang_code\n            # Always set cookie\n            response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code,\n                                max_age=settings.LANGUAGE_COOKIE_AGE,\n                                path=settings.LANGUAGE_COOKIE_PATH,\n                                domain=settings.LANGUAGE_COOKIE_DOMAIN)\n    return response\n\n\ndef logout_view(request):\n    logout(request)\n    return http.HttpResponseRedirect('/')\n\n\ndef get_url_by_role(role, first_login):\n    obj = next((hook for hook in RoleBasedRedirectHook().registered_hooks\n                if hook.role == role and hook.first_login == first_login), None)\n\n    if obj is None and first_login:\n        # If it is the first_login, do a fallback to find the non-first login behaviour when it is\n        # not available\n        obj = next((hook for hook in RoleBasedRedirectHook().registered_hooks\n                    if hook.role == role and hook.first_login is False), None)\n\n    if obj:\n        return obj.url\n\n\nclass GuestRedirectView(View):\n    def get(self, request):\n        \"\"\"\n        Redirects a guest user to a learner accessible page.\n        \"\"\"\n        return HttpResponseRedirect(get_url_by_role(user_kinds.LEARNER, False))\n\n\nclass RootURLRedirectView(View):\n\n    def get(self, request):\n        \"\"\"\n        Redirects user based on the highest role they have for which a redirect is defined.\n        \"\"\"\n        first_login = request.session.get(\"first_login\", False)\n        if request.user.is_authenticated():\n            url = None\n            if request.user.is_superuser:\n                url = url or get_url_by_role(user_kinds.SUPERUSER, first_login)\n            roles = set(Role.objects.filter(user_id=request.user.id).values_list('kind', flat=True).distinct())\n            if user_kinds.ADMIN in roles:\n                url = url or get_url_by_role(user_kinds.ADMIN, first_login)\n            if user_kinds.COACH in roles:\n                url = url or get_url_by_role(user_kinds.COACH, first_login)\n            url = url or get_url_by_role(user_kinds.LEARNER, first_login)\n        else:\n            url = get_url_by_role(user_kinds.ANONYMOUS, first_login)\n        if url:\n            return HttpResponseRedirect(url)\n        raise Http404(_(\"No appropriate redirect pages found, it is likely that Kolibri is badly configured\"))\n", "path": "kolibri/core/views.py"}]}