2017-11-23 2 views
0

AngularJS를 처음 사용하고 AngularJs로 Django를 설정하려고했지만이 두 프레임 워크로 라우팅을 처리 할 때 몇 가지 문제가 있습니다. 나는 그것이 작동하고 나에게 파일을 보여줍니다,하지만 난 app.js에서 쓴 내가 http://localhost:8000/test을 실행할 때 그것은 나에게 표준 장고 404 오류를 제공 http://localhost:8000/index.html을 실행하면django와 AngularJS 라우팅

: 지금까지 나는 아래와 같이 설정했습니다.

무엇이 누락 되었습니까? urls.py

urlpatterns = [ 
    url(r'^index.html/$', 
] 

는 app.js

var app = angular.module("myApp", ["ngRoute"]); 
app.config(function($routeProvider) { 
    $routeProvider 
    .when("/test", { 
     templateUrl : "index.html", 
     controller: "MainCtrl" 
    }) 
}); 

app.controller("MainCtrl", function ($scope) { 
    $scope.msg = "test"; 
}); 

index.html을

{% load static %} 
<html ng-app="myApp"> 

<head> 
</head> 

<body> 
    <div> 
     test 
    </div> 
    <script src="{% static 'js/general/angular.min.js' %}" type="text/javascript"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script> 
    <script type="text/javascript" src="{% static 'js/app.js' %}"></script> 
</body> 

</html> 

답변

1

당신은 URL을 정의 할 필요 해당하는 뷰 메서드입니다. views.py

def test(request): 
    return HttpResponse('You are looking at test') 
에서

url(r'^test/$', views.test, name='test') 

: 당신이 을 urls.py를에서

당신은 같은 뭔가가 필요