i have starting building application in angularjs , django, , after creating login page, trying redirect application new url after successful login. using $location variable redirect page. here code:
$scope.login = function() { $http({ method: 'post', data: { username: $scope.username, password: $scope.password }, url: '/pos/login_authentication/' }).then(function successcallback(response) { user = response.data console.log(response.data) if (user.is_active) { $location.url("dashboard") } }, function errorcallback(response) { console.log('errorcallback') }); } my initial url http://localhost:8000/pos/, , after hitting log in button, above function calls, , redirected http://localhost:8000/pos/#/dashboard. unable catch url in regex pattern in urls.py file:
my project urls.py file:
from django.conf.urls import url, include django.contrib import admin urlpatterns = [ url(r'^pos/', include('pos.urls')), url(r'^admin/', admin.site.urls), ] and pos application's urls.py file:
urlpatterns = [ url(r'^$', views.index, name='index'), url(r'^login_authentication/$', views.login_authentication, name='login_authentication'), url(r'^#/dashboard/$', views.dashboard, name='dashboard') ] using this, getting same login page on visiting http://localhost:8000/pos/#/dashboard link. means in urls.py file of pos application, mapping http://localhost:8000/pos/#/dashboard first object of urlpatterns:url(r'^$', views.index, name='index'). how make python differentiate between both links?
you have major misunderstanding , anchor in url. anchor called officially fragment identifier, it's not part of main url, if have # when visit url http://localhost:8000/pos/#/dashboard, browser treat remaining #/dashboard anchor in page http://localhost:8000/pos/ renders. shouldn't using in urls.py definition. please read link above more usage of anchor.
Comments
Post a Comment