Answer the question
In order to leave comments, you need to log in
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) {
};
class TicketForm(ModelForm):
class Meta:
model = Tickets
fields = '__all__'
def AddTicket(request):
form = TicketForm()
return render(request, 'AddTicket.html', {'form': form})
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)),
]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question