0

i got Django server with

urls.py

urlpatterns = [
  url('^', IndexView.as_view(), name='index')
]

landing/urls.py

urlpatterns = [
  url(r'^admin/', admin.site.urls),
  url('^.*', include("landing.urls"))
]

views.py

class IndexView(TemplateView):
template_name = 'landing/header.html'

def get_context_data(self, **kwargs):
    context = super(IndexView, self).get_context_data(**kwargs)
    context['meals'] = get_data()

    return context

header.html

<html lang="en" ng-app="KolyadaApp">

<div ng-view></div>
<a class="navbar-brand" ng-href="/landing">landing</a>
<a ng-href="#/menu">menu</a>
<a ng-href="#/week">week</a>

app.js

'use strict';

/* Controllers */
var KolyadaApp = angular.module('KolyadaApp', ['ngRoute',    'ngResource']);

angular.
  module('KolyadaApp').
  config(['$locationProvider', '$routeProvider', '$interpolateProvider',
    function config($locationProvider, $routeProvider, $interpolateProvider) {
    $interpolateProvider.startSymbol('{$');
    $interpolateProvider.endSymbol('$}');

    $routeProvider.
        when('/', {
            templateUrl: function(route) {

                console.log(route);

                return '/';
            }
        }).
        when('/menu', {
          templateUrl: '/menu.html'
        }).
        when('/week', {
          templateUrl: '/week.html'
        }).
        otherwise('/', {
            redirectTo:'/'
        });
}
]);

What I got: after loading page, I can do nothing with links, Console log periodically tells me about call stack overflow. And it hard to close the tab.

Well, after some time of searching answer, and placing '/' everywhere where I can, I decide to ask you. Please tell where I'm wrong.

Thank you.

8
  • Why do you think issue is due to router? Looks straightforward enough Commented Jun 26, 2016 at 19:11
  • well, I don't except that I just use 'router' wrong, but this code is simple, and it doesn't work. I don't know, what to do and how to debug it, googling didn't give me answer. And the last thing I add to code was routing. if you see I tried to use function to debug =) Commented Jun 26, 2016 at 19:55
  • Understand...that last comment may help.. that problem didn't start until added router. That's why I asked. The otherwise looks wrong, try change to otherwise({ redirectTo:'/' }) Commented Jun 26, 2016 at 19:59
  • Oh...also doesn't make sense there is no template path in main route. Would mean you load page into itself. Try using one of the other templates on that one for now Commented Jun 26, 2016 at 20:02
  • 1
    I have encountered this error and the cause is a missing template. Please check if your templateUrls point to an existing one. Commented Jun 27, 2016 at 1:33

1 Answer 1

1

This is your issue, I believe:

urls.py

urlpatterns = [
  url('^', IndexView.as_view(), name='index')
]

landing/urls.py

urlpatterns = [
  url(r'^admin/', admin.site.urls),
  url('^.*', include("landing.urls"))  # Circular reference
]

You're reloading landing.urls inside your include tag everytime you load landing/urls.py.

Did you mean for that line to be in urls.py? If so you'll need to alter one or both so they don't conflict (i.e. ^ and ^.* both match an empty string).

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.