D
D
Dmitry2015-01-03 18:26:31
Django
Dmitry, 2015-01-03 18:26:31

How to pass not a template, but a response from Django to the Angular route?

I recently started learning Angular. There are some questions, I ask for help from veterans)
It is necessary to make the control panel in the form of a single-page application
The choice fell on Angular (actually, I did not consider others, since the name was well-known).
Did a bit of fiddling around with Angular route...
Angular js

var myApp = angular.module('myApp', ['ngRoute']);

myApp.controller('IndexCtrl', IndexCtrl).controller('AddTicketCtrl', AddTicketCtrl);

myApp.config(function($routeProvider, $locationProvider) {
  $routeProvider.when("{% url 'home' %}", {
    templateUrl: "{% static 'templates/index.html' %}",
    controller: 'IndexCtrl',
    title: 'Главная'
  }).when("{% url 'add-ticket' %}", {
    templateUrl: "{% static 'templates/add_ticket.html' %}",
    controller: 'AddTicketCtrl',
    title :'Новый билет'
  });
  $locationProvider.html5Mode({enabled: true, requireBase: false});
});
function IndexCtrl($scope, $routeParams) {
};
function AddTicketCtrl($scope, $routeParams) {
};

views.py
class TicketForm(ModelForm):
    class Meta:
        model = Tickets
        fields = '__all__'
def AddTicket(request):
    form = TicketForm()
    return render(request, 'AddTicket.html', {'form': form})

urls.py
workplace_urls = [
    url(r'^$', views.WorkPlace, name='home'),
    url(r'^tickets/add/$', views.AddTicket, name='add-ticket'),
]

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^workplace/', include(workplace_urls)), 
]

So when I follow the link 'workplace/tickets/add/', then the answer is not added to ng-view, but an empty page with a form opens.
I found an article using ui.router , but I would not want to complicate my life with libraries in addition to the already complicated Angular!
In general, you need to insert the rendered form into ng-view. How to do it? Or are there alternatives?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question