Python 使用django和AngularJS进行路由
我刚接触AngularJS,并尝试使用AngularJS设置Django,但是,我在使用这两个框架处理路由时遇到了一些问题。到目前为止,我的设置如下所示: 当我运行Python 使用django和AngularJS进行路由,python,angularjs,django,Python,Angularjs,Django,我刚接触AngularJS,并尝试使用AngularJS设置Django,但是,我在使用这两个框架处理路由时遇到了一些问题。到目前为止,我的设置如下所示: 当我运行http://localhost:8000/index.html它工作并向我显示文件,但当我运行http://localhost:8000/test正如我在app.js中所写,它给出了标准的Django 404错误 我错过了什么 url.py urlpatterns = [ url(r'^index.html/$', ]
http://localhost:8000/index.html
它工作并向我显示文件,但当我运行http://localhost:8000/test
正如我在app.js
中所写,它给出了标准的Django 404错误
我错过了什么
url.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>
{%load static%}
测验
您需要定义URL及其相应的视图方法
在你的URL.py
你需要像这样的东西:
url(r'^test/$', views.test, name='test')
In views.py
def test(request):
return HttpResponse('You are looking at test')