How to coordinate url.py in Django + Django REST and routing in Angular JS ? Site root / does not see the error that the page was not found. Task: through Django, use api to fill templates with data, through Angular to organize a transition between pages with passing parameters.

 Using the URLconf defined in myproject.urls, Django tried these URL patterns, in this order: ^db_api/ ^media\/(?P<path>.*)$ ^static\/(?P<path>.*)$ The current URL, , didn't match any of these. 

Routing in Angulyar:

 angular('myApp', ['ngRouter']); angular .module('myApp') .config(stateConfig); stateConfig.$inject = ['$routerProvider', 'DJANGO_SETTINGS']; function stateConfig($stateProvider, DJANGO_SETTINGS) { $routeProvider .when('/', { controller: 'someController1', templateUrl: DJANGO_SETTINGS.staticUrl + 'myproject/templates/template1.html' } .when('/page1/:id', { controller: 'someController2', templateUrl: DJANGO_SETTINGS.staticUrl + 'myproject/templates/template2.html' } }; 

in the main urls.py for myproject:

 urlpatterns = patterns('', url(r'^db_api/', include("db_manager.urls")), ) + static.static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + static.static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) 

in db_manager urls.py:

 urlpatterns = patterns( url(r'^info', InfoDbAPI.as_view()) 

Update:

Added by:

In urls.py :

 url(r'^$', HomePageView.as_view(), name='home') 

In views.py :

 class HomePageView(TemplateView): template_name = "index.html" 

In index.html , the script with the angular routing and the script with the controllers are connected. When you go to the site root, index.html opens, but the routing does not work. When switching to /page1/1 an error is issued that such a path is not registered in urls.py Those. Angular routing does not work.

And it is also not clear if I have a basic template in which basic scripts are connected, i.e. common for everyone, there is a certain index.html, an extension of the basic template in which the script is connected with the routing of the angulyar and its controllers for each page, and there are two templates that should be opened based on the routing rules of the angular. What structure should these templates have if they were originally extensions of index.html, i.e. used his scripts, the scripts of the base template.

Those. base.html:

 {% load staticfiles %} <!DOCTYPE html> ... подключение общих скриптов, таблиц стилей </html> 

index.html:

 {% extends 'base.html' %} {% load staticfiles %} подключение скриптов, в частности, с контроллерами ангуляра, таблиц стилей, скрипт с роутингом ангуляра 

template1.html:

 {% extends 'index.html' %} <div ng-app="myApp"> ... </div> 

    1 answer 1

    If I understand you correctly, then you should add a pattern for the root page (/) in urls.py , make some TemplateView , which will open a certain index.html , in which your Angular already connected and then it does everything itself

    In urls.py :

     url(r'^$', HomePageView.as_view(), name='home') 

    In views.py :

     class HomePageView(TemplateView): template_name = "index.html" 
    • did so, now the root - this is the index opens, but the routing of the angular does not work. when attempting to switch to /page1/1 an error is urls.py that there is no such way in urls.py Ie, if I understand correctly, angular does not handle the path - Emm