0

So, I was integrating AngularJS with a Django backend.

For loading the HTML partials/templates I am using angularjs' ui-router. Here's my angularjs code:

function config($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) {
    $stateProvider.state("home", {
        url: "",
        controller: "HomeCtrl as home",
        templateUrl: "/static/templates/home.html"
    })
    .state("feed", {
        url: "/feed",
        controller: "FeedCtrl as feed",
        templateUrl: "/static/templates/feed.html"
    })
}

My home state loads fine. But when I try to load the feed state, I get the following error:

I am guessing Django is interfering with angularjs' routing? How do I handle this?

4
  • 1
    How are you trying to load feed state? By entering URL directly or clicking some link when home state is loaded? Commented Sep 21, 2015 at 11:34
  • entering url directly? Should this matter? Commented Sep 21, 2015 at 11:35
  • Ok got it! should have entered 'baseurl/#/feed' instead of 'baseurl/feed'. Thanks! :) Commented Sep 21, 2015 at 11:36
  • If you're entering directly that URL, AngularJS can't catch it because it is not loaded. If you want to have URLs without #, you should return same angular template from django when entering any URL managed by angularjs directly Commented Sep 21, 2015 at 11:39

1 Answer 1

1

Django have to handle "feed" state same way as "home" state.

url(r'^(feed)?$', "your_app.views.home")

The best way is probably handle all remaining urls by home view and deal with it in angular later. Add this at the last line of your urls.py

url(r'^.*$', "your_app.views.home", name='home'),

And do not forgot activete HTML5 mode

$locationProvider.html5Mode(true);
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.