首页 > 代码库 > angular route 与 django urls 冲突怎么解决?

angular route 与 django urls 冲突怎么解决?

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: "<student-detail></student-detail>",
              }).
              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<template_name>\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没获取到路由请求吗?该如何解决?谢谢。


angular route 与 django urls 冲突怎么解决? >> python

这个答案描述的挺清楚的:
http://www.goodpm.net/postreply/python/1010000008991595/angularroute与djangourls冲突怎么解决.html

angular route 与 django urls 冲突怎么解决?