全部博文(788)
分类: 敏捷开发
2017-06-11 14:17:04
app.js
var app = angular.module('app', [ 'ngResource', 'ngRoute', // 'ui.bootstrap', // 'ngResource', 'student', ]); app.config( function( $locationProvider, $routeProvider ){ $locationProvider.html5Mode({ enabled:true }) $routeProvider. when("/", { template: 'base', }). when("/student/1", { template: "", }). otherwise({ template: "Not Found" }) });
student.js
var app = angular.module('student', []); app.component('studentDetail',{ templateUrl:'studentDetail.html', controller: function($scope) { $scope.test = 'Got it.' } });
urls.py
class SimpleStaticView(TemplateView): def get_template_names(self): return [self.kwargs.get('template_name') + ".html"] urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^api/', include("students.api.urls", namespace='students-api')), url(r'^(?P\w+)$', SimpleStaticView.as_view(), name='example'), url(r'^$', TemplateView.as_view(template_name='home.html')), ] if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
测试,当访问/,base字段是出现的,说明ng-view工作 正常,但当访问/students/1时,返回django路由报错,未找到该路由。
studentDetail.html是存在的。
这是angular没获取到路由请求吗?该如何解决?谢谢。