我有一个Django Web应用程序,带有Angular前端。在我的登录页面上,我有一个忘记密码链接,它会将您带到您输入电子邮件的表单中。这将发送一封带有重置网址的电子邮件。问题的关键在于,当用户点击他们在电子邮件中收到的链接,或者将其复制/粘贴到Web浏览器中时,它会先查找Django网址,然后再查找角度路由。一旦应用程序进入角度javascript,url将起作用,但如果直接从电子邮件中直接进入该链接,则它不起作用,因为没有Django URL,并且Angular没有'尚未感动。我希望这是有道理的。例如,这里是网址的样子
http://domain-name/dportal/#/reset_password/d7/4oe-0f63050ac947ba024563
Django网址应用首先尝试
# Webapp Urls
urlpatterns = [
url(r'^dportal/', include('dealer_portal.urls')),
url(r'^views/(?P<page_name>[-\w]+.html)/?$', webapp_views.angular_views),
url(r'^simple_page/(?P<page_name>[-\w]+.html)/?$', webapp_views.simple_page),
url(r'^home/', webapp_views.home, name='home'),
url(r'^admin/', admin.site.urls),
url(r'^account/', include('account.ajax_urls')),
url(r'^vehicle/', include('vehicle.ajax_urls')),
url(r'^messages/', include('messaging.ajax_urls')),
url(r'^dealer/', include('dealer.ajax_urls')),
url(r'^api/homenet/test/', 'data_feed_homenet.views.test_conveyor_interface', name='api_homenet_test'),
url(r'^api/homenet/', 'data_feed_homenet.views.conveyor_interface', name='api_homenet'),
url('', include('social.apps.django_app.urls', namespace='social'))
]
# dealer_portal urls
urlpatterns = [
url(r'^home', home, name='home'),
url(r'^views/(?P<page_name>[-\w]+.html)/?$', angular_views, name='angular_views'),
url(r'^login', authenticate_user, name='auth_user'),
url(r'^sign-out', sign_out, name='sign_out'),
url(r'^getInventory', getVehicleInventory, name='get_inventory'),
url(r'^dealer-threads', dealer_threads, name='dealer_threads'),
url(r'^recent-messages', recent_messages, name='recent_messages'),
url(r'^new-leads', new_leads, name='new_leads'),
url(r'^assign-leads', assign_leads, name='assign_leads'),
url(r'^get_customer/(?P<user_id>.*)/?$', get_customer, name='get_customer'),
url(r'^get_employee/(?P<user_id>.*)/?$', get_employee, name='get_employees'),
url(r'^add-employee', add_employee, name='add_employee'),
url(r'^get-employees/', get_employees, name='get_employees'),
url(r'^update-employees', update_employees, name='update_employees'),
url(r'^delete-employees', delete_employees, name='delete_employees'),
url(r'^create-thread', create_thread, name='create_thread'),
url(r'^messages/(?P<thread_id>.*)/?$', get_messages, name='get_messages'),
url(r'^new-message', new_message, name='new_message'),
url(r'^get-user-selections/(?P<veh_id>.*)/?$', user_selections, name='user_selections'),
url(r'^get-hours', get_hours, name='get_hours'),
url(r'^save-hours', save_hours, name='save_hours'),
url(r'^dealer', dealer_info, name='dealer_info'),
url(r'^save-dealer-info', save_dealer, name='save_dealer'),
url(r'^search-by-vin', search_by_vin, name='search_by_vin'),
url(r'^save-holiday', save_holiday, name='save_holiday'),
url(r'^.*$', portal_main, name='dealer_portal_home'),
]
Angular app配置
/* eslint no-alert: 0 */
'use strict';
var app = angular.module('SocialAutoDealerPortalApp', [
'ngRoute',
'ngSanitize',
'mobile-angular-ui',
'mobile-angular-ui.gestures',
'ui.bootstrap',
'SocialAutoDealerPortalApp.controllers'
]);
app.run(function ($http, $transform, $rootScope, $window, $location, $route, SharedState) {
console.log('App Running');
});
var portal_controllers = angular.module('SocialAutoDealerPortalApp.controllers', []);
// this allows our ajax requests to work with django by providing the security token
app.config(['$httpProvider', function ($httpProvider) {
$httpProvider.defaults.xsrfCookieName = 'csrftoken';
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
}]);
app.config(function ($routeProvider) {
$routeProvider.when('/', {
templateUrl: 'views/portal_home.html',
reloadOnSearch: false,
controller: 'portalHome'
});
$routeProvider.when('/sign-in', {
templateUrl: 'views/sign-in.html',
reloadOnSearch: false,
controller: 'dealer_signin'
});
$routeProvider.when('/recover-pw', {
templateUrl: 'views/forgot_password.html',
reloadOnSearch: false,
controller: 'passwordRecover'
});
$routeProvider.when('/reset_password/:user/:reset_code', {
templateUrl: 'views/reset_password.html',
reloadOnSearch: false,
controller: 'passwordReset'
});
$routeProvider.when('/info', {
templateUrl: 'views/info-hours.html',
reloadOnSearch: false,
controller: 'infoHours'
});
$routeProvider.when('/inventory', {
templateUrl: 'views/inventory.html',
reloadOnSearch: false,
controller: 'inventory'
});
$routeProvider.when('/vehicle/:vid', {
templateUrl: 'views/vehicle_userlist.html',
reloadOnSearch: false,
controller: 'vehicleSelections'
});
$routeProvider.when('/user/:uid', {
templateUrl: 'views/user_activitylist.html',
reloadOnSearch: false,
controller: 'portalProfile'
});
$routeProvider.when('/employee/:uid', {
templateUrl: 'views/employee_profile.html',
reloadOnSearch: false,
controller: 'portalEmployee'
});
$routeProvider.when('/manage-employees', {
templateUrl: 'views/manage_users.html',
reloadOnSearch: false,
controller: 'manageUsers'
});
$routeProvider.when('/leads/', {
templateUrl: 'views/threads.html',
reloadOnSearch: false,
controller: 'portalThreads'
});
$routeProvider.when('/messages/:mid', {
templateUrl: 'views/message.html',
reloadOnSearch: false,
controller: 'portalChat'
});
});
更新 我更改了我的应用配置,如果我将网址复制/粘贴到浏览器中,它就可以正常工作。如果我只是点击电子邮件中的链接,它就不会。它会转到网址,但会快速重定向到登录页面。