0

I new to AngularJS and trying to set up Django with AngularJs, however, I have some issues with handling the routing with those two frameworks. so far I've set up like below:

When I run http://localhost:8000/index.html it works and shows me the file, but when I run http://localhost:8000/test as I wrote in app.js it gives me standard Django 404 error.

What am I missing?

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 Answer 1

1

You need to define the URL and it's corresponding views method.

In you urls.py You need something like:

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

In views.py

def test(request):
    return HttpResponse('You are looking at test')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.